1
0
Fork 0
mirror of https://github.com/veekun/pokedex.git synced 2024-08-20 18:16:34 +00:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Evan Fuhr 2019-01-03 20:39:26 -06:00
commit 496b5098de
15 changed files with 4169 additions and 2115 deletions

View file

@ -8,5 +8,7 @@ python:
install: pip install -e .
before_script: pokedex setup -v
script: py.test
script:
- py.test
- pokedex dump -l all
sudo: false

View file

@ -1,19 +1,36 @@
generation_id,local_language_id,name
1,1,だいいっせだい
1,5,Génération I
1,6,Generation I
1,9,Generation I
1,11,第一世代
2,1,だいにせだい
2,5,Génération II
2,6,Generation II
2,9,Generation II
2,11,第二世代
3,1,だいさんせだい
3,5,Génération III
3,6,Generation III
3,9,Generation III
3,11,第三世代
4,1,だいよんせだい
4,5,Génération IV
4,6,Generation IV
4,9,Generation IV
4,11,第四世代
5,1,だいごせだい
5,5,Génération V
5,6,Generation V
5,9,Generation V
5,11,第五世代
6,1,だいろくせだい
6,5,Génération VI
6,6,Generation VI
6,9,Generation VI
6,11,第六世代
7,1,だいななせだい
7,5,Génération VII
7,6,Generation VII
7,9,Generation VII
7,11,第七世代

1 generation_id local_language_id name
2 1 1 だいいっせだい
3 1 5 Génération I
4 1 6 Generation I
5 1 9 Generation I
6 1 11 第一世代
7 2 1 だいにせだい
8 2 5 Génération II
9 2 6 Generation II
10 2 9 Generation II
11 2 11 第二世代
12 3 1 だいさんせだい
13 3 5 Génération III
14 3 6 Generation III
15 3 9 Generation III
16 3 11 第三世代
17 4 1 だいよんせだい
18 4 5 Génération IV
19 4 6 Generation IV
20 4 9 Generation IV
21 4 11 第四世代
22 5 1 だいごせだい
23 5 5 Génération V
24 5 6 Generation V
25 5 9 Generation V
26 5 11 第五世代
27 6 1 だいろくせだい
28 6 5 Génération VI
29 6 6 Generation VI
30 6 9 Generation VI
31 6 11 第六世代
32 7 1 だいななせだい
33 7 5 Génération VII
34 7 6 Generation VII
35 7 9 Generation VII
36 7 11 第七世代

View file

@ -5,4 +5,4 @@ id,main_region_id,identifier
4,4,generation-iv
5,5,generation-v
6,6,generation-vi
7,7,sun-moon
7,7,generation-vii

1 id main_region_id identifier
5 4 4 generation-iv
6 5 5 generation-v
7 6 6 generation-vi
8 7 7 sun-moon generation-vii

View file

@ -246,10 +246,12 @@ location_id,generation_id,game_index
263,4,2011
264,4,2012
264,6,2
264,7,2
265,4,3000
266,4,3001
267,4,3002
267,6,4
267,7,4
268,4,3003
269,4,3004
270,4,3005
@ -441,6 +443,62 @@ location_id,generation_id,game_index
426,5,114
427,5,115
428,5,116
429,6,184
430,6,186
431,6,194
432,6,196
433,6,198
434,6,200
435,6,272
436,6,274
437,6,280
438,6,282
439,6,286
440,6,288
441,6,290
442,6,294
443,6,296
444,6,298
445,6,300
446,6,302
448,6,316
449,6,204
450,6,206
451,6,208
452,6,210
453,6,212
454,6,214
455,6,216
456,6,218
457,6,220
458,6,222
459,6,224
460,6,226
461,6,228
462,6,230
463,6,232
464,6,234
465,6,236
466,6,238
467,6,240
468,6,242
469,6,244
470,6,246
471,6,248
472,6,250
473,6,252
474,6,254
475,6,256
476,6,258
477,6,260
478,6,262
479,6,264
480,6,266
481,6,268
482,6,270
483,6,324
484,6,174
485,6,182
531,5,117
532,5,118
533,5,119
@ -477,6 +535,24 @@ location_id,generation_id,game_index
564,5,151
565,5,152
566,5,153
567,6,170
568,6,172
569,6,176
570,6,178
571,6,180
572,6,188
573,6,190
574,6,192
576,6,284
577,6,330
578,6,320
579,6,310
580,6,312
581,6,306
582,6,278
583,6,308
584,6,276
585,6,354
587,6,6
588,6,8
589,6,9
@ -581,3 +657,112 @@ location_id,generation_id,game_index
688,6,164
689,6,166
690,6,168
691,6,202
692,6,292
693,6,304
694,6,314
695,6,318
696,6,322
697,6,326
698,6,328
699,6,332
700,6,334
701,6,336
702,6,338
703,6,340
704,6,342
705,6,344
706,6,346
707,6,348
708,6,350
709,6,352
710,7,6
711,7,8
712,7,10
713,7,12
714,7,14
715,7,16
716,7,18
717,7,20
718,7,22
719,7,24
720,7,26
721,7,28
722,7,30
723,7,34
724,7,36
725,7,38
726,7,40
727,7,42
728,7,44
729,7,46
730,7,48
731,7,50
732,7,52
733,7,54
734,7,56
735,7,58
736,7,60
737,7,62
737,7,102
738,7,64
739,7,66
740,7,68
741,7,70
742,7,72
743,7,74
744,7,76
745,7,78
746,7,82
747,7,84
748,7,86
749,7,88
750,7,90
751,7,92
752,7,94
753,7,100
754,7,104
755,7,106
756,7,108
757,7,110
758,7,112
759,7,114
760,7,116
761,7,118
762,7,120
763,7,122
764,7,124
765,7,126
766,7,128
767,7,130
768,7,132
769,7,134
770,7,136
771,7,138
772,7,140
773,7,142
774,7,144
775,7,146
776,7,148
777,7,150
778,7,152
779,7,154
780,7,156
781,7,158
782,7,160
783,7,162
784,7,164
785,7,166
786,7,168
787,7,170
788,7,172
789,7,174
790,7,176
791,7,178
792,7,180
793,7,182
794,7,184
795,7,186
796,7,188
797,7,190
798,7,192

1 location_id generation_id game_index
246 263 4 2011
247 264 4 2012
248 264 6 2
249 264 7 2
250 265 4 3000
251 266 4 3001
252 267 4 3002
253 267 6 4
254 267 7 4
255 268 4 3003
256 269 4 3004
257 270 4 3005
443 426 5 114
444 427 5 115
445 428 5 116
446 429 6 184
447 430 6 186
448 431 6 194
449 432 6 196
450 433 6 198
451 434 6 200
452 435 6 272
453 436 6 274
454 437 6 280
455 438 6 282
456 439 6 286
457 440 6 288
458 441 6 290
459 442 6 294
460 443 6 296
461 444 6 298
462 445 6 300
463 446 6 302
464 448 6 316
465 449 6 204
466 450 6 206
467 451 6 208
468 452 6 210
469 453 6 212
470 454 6 214
471 455 6 216
472 456 6 218
473 457 6 220
474 458 6 222
475 459 6 224
476 460 6 226
477 461 6 228
478 462 6 230
479 463 6 232
480 464 6 234
481 465 6 236
482 466 6 238
483 467 6 240
484 468 6 242
485 469 6 244
486 470 6 246
487 471 6 248
488 472 6 250
489 473 6 252
490 474 6 254
491 475 6 256
492 476 6 258
493 477 6 260
494 478 6 262
495 479 6 264
496 480 6 266
497 481 6 268
498 482 6 270
499 483 6 324
500 484 6 174
501 485 6 182
502 531 5 117
503 532 5 118
504 533 5 119
535 564 5 151
536 565 5 152
537 566 5 153
538 567 6 170
539 568 6 172
540 569 6 176
541 570 6 178
542 571 6 180
543 572 6 188
544 573 6 190
545 574 6 192
546 576 6 284
547 577 6 330
548 578 6 320
549 579 6 310
550 580 6 312
551 581 6 306
552 582 6 278
553 583 6 308
554 584 6 276
555 585 6 354
556 587 6 6
557 588 6 8
558 589 6 9
657 688 6 164
658 689 6 166
659 690 6 168
660 691 6 202
661 692 6 292
662 693 6 304
663 694 6 314
664 695 6 318
665 696 6 322
666 697 6 326
667 698 6 328
668 699 6 332
669 700 6 334
670 701 6 336
671 702 6 338
672 703 6 340
673 704 6 342
674 705 6 344
675 706 6 346
676 707 6 348
677 708 6 350
678 709 6 352
679 710 7 6
680 711 7 8
681 712 7 10
682 713 7 12
683 714 7 14
684 715 7 16
685 716 7 18
686 717 7 20
687 718 7 22
688 719 7 24
689 720 7 26
690 721 7 28
691 722 7 30
692 723 7 34
693 724 7 36
694 725 7 38
695 726 7 40
696 727 7 42
697 728 7 44
698 729 7 46
699 730 7 48
700 731 7 50
701 732 7 52
702 733 7 54
703 734 7 56
704 735 7 58
705 736 7 60
706 737 7 62
707 737 7 102
708 738 7 64
709 739 7 66
710 740 7 68
711 741 7 70
712 742 7 72
713 743 7 74
714 744 7 76
715 745 7 78
716 746 7 82
717 747 7 84
718 748 7 86
719 749 7 88
720 750 7 90
721 751 7 92
722 752 7 94
723 753 7 100
724 754 7 104
725 755 7 106
726 756 7 108
727 757 7 110
728 758 7 112
729 759 7 114
730 760 7 116
731 761 7 118
732 762 7 120
733 763 7 122
734 764 7 124
735 765 7 126
736 766 7 128
737 767 7 130
738 768 7 132
739 769 7 134
740 770 7 136
741 771 7 138
742 772 7 140
743 773 7 142
744 774 7 144
745 775 7 146
746 776 7 148
747 777 7 150
748 778 7 152
749 779 7 154
750 780 7 156
751 781 7 158
752 782 7 160
753 783 7 162
754 784 7 164
755 785 7 166
756 786 7 168
757 787 7 170
758 788 7 172
759 789 7 174
760 790 7 176
761 791 7 178
762 792 7 180
763 793 7 182
764 794 7 184
765 795 7 186
766 796 7 188
767 797 7 190
768 798 7 192

File diff suppressed because it is too large Load diff

View file

@ -519,11 +519,11 @@ id,region_id,identifier
535,5,join-avenue
536,5,floccesy-town
537,5,lentimas-town
538,5,route-19
539,5,route-20
540,5,route-21
541,5,route-22
542,5,route-23
538,5,unova-route-19
539,5,unova-route-20
540,5,unova-route-21
541,5,unova-route-22
542,5,unova-route-23
543,5,castelia-sewers
544,5,floccesy-ranch
545,5,virbank-complex
@ -638,8 +638,8 @@ id,region_id,identifier
654,6,dernière-way
655,6,kalos-route-22
656,6,detourner-way
657,6,victory-road
658,6,pokemon-league
657,6,kalos-victory-road
658,6,kalos-pokemon-league
659,6,kiloude-city
660,6,battle-maison
661,6,azure-bay
@ -672,3 +672,111 @@ id,region_id,identifier
688,6,kiloude-station
689,6,ambrette-aquarium
690,6,unknown-dungeon
691,3,hoenn-pokemon-league
692,3,team-aqua-hideout
693,3,sea-mauville
694,3,team-magma-hideout
695,3,battle-resort
696,3,ss-tidal
697,3,mirage-forest
698,3,mirage-cave
699,3,mirage-mountain
700,3,trackless-forest
701,3,pathless-plain
702,3,nameless-cavern
703,3,fabled-cave
704,3,gnarled-den
705,3,crescent-isle
706,3,secret-islet
707,3,soaring-in-the-sky
708,3,secret-shore
709,3,secret-meadow
710,7,alola-route-1--hauoli-outskirts
711,7,alola-route-1
712,7,alola-route-3
713,7,alola-route-2
714,7,kalae-bay
715,7,melemele-sea
716,7,hauoli-city--beachfront
717,7,hauoli-city--shopping-district
718,7,hauoli-city--marina
719,7,iki-town
720,7,mahalo-trail
721,7,mahalo-trail--plank-bridge
722,7,ruins-of-conflict
723,7,ten-carat-hill
724,7,ten-carat-hill--farthest-hollow
725,7,hauoli-cemetery
726,7,melemele-meadow
727,7,seaward-cave
728,7,berry-fields
729,7,verdant-cavern--trial-site
730,7,verdant-cavern--totems-den
731,7,alola-route-4
732,7,alola-route-5
733,7,alola-route-6
734,7,alola-route-7
735,7,alola-route-8
736,7,alola-route-9
737,7,hano-grand-resort
738,7,hano-beach
739,7,akala-meadow
740,7,paniola-town
741,7,heahea-city
742,7,konikoni-city
743,7,royal-avenue
744,7,memorial-hill
745,7,paniola-ranch
746,7,wela-volcano-park
747,7,wela-volcano-park--totems-den
748,7,brooklet-hill
749,7,brooklet-hill--totems-den
750,7,lush-jungle
751,7,ruins-of-life
752,7,akala-outskirts
753,7,digletts-tunnel
754,7,battle-royal-dome
755,7,alola-route-10
756,7,alola-route-11
757,7,secluded-shore
758,7,alola-route-13
759,7,tapu-village
760,7,alola-route-15
761,7,alola-route-16
762,7,alola-route-17
763,7,alola-route-12
764,7,haina-desert
765,7,alola-route-14
766,7,ulaula-meadow
767,7,po-town
768,7,malie-city
769,7,malie-garden
770,7,mount-hokulani
771,7,blush-mountain
772,7,ruins-of-abundance
773,7,lake-of-the-sunne
774,7,lake-of-the-moone
775,7,mount-lanakila
776,7,shady-house
777,7,thrifty-megamart--abandoned-site
778,7,hokulani-observatory
779,7,alola-pokemon-league
780,7,poni-meadow
781,7,poni-wilds
782,7,ancient-poni-path
783,7,poni-breaker-coast
784,7,poni-grove
785,7,poni-plains
786,7,poni-coast
787,7,poni-gauntlet
788,7,seafolk-village
789,7,vast-poni-canyon
790,7,altar-of-the-sunne
791,7,altar-of-the-moone
792,7,ruins-of-hope
793,7,resolution-cave
794,7,exeggutor-island
795,7,battle-tree
796,7,aether-paradise
797,7,ultra-space
798,7,malie-city--outer-cape

1 id region_id identifier
519 535 5 join-avenue
520 536 5 floccesy-town
521 537 5 lentimas-town
522 538 5 route-19 unova-route-19
523 539 5 route-20 unova-route-20
524 540 5 route-21 unova-route-21
525 541 5 route-22 unova-route-22
526 542 5 route-23 unova-route-23
527 543 5 castelia-sewers
528 544 5 floccesy-ranch
529 545 5 virbank-complex
638 654 6 dernière-way
639 655 6 kalos-route-22
640 656 6 detourner-way
641 657 6 victory-road kalos-victory-road
642 658 6 pokemon-league kalos-pokemon-league
643 659 6 kiloude-city
644 660 6 battle-maison
645 661 6 azure-bay
672 688 6 kiloude-station
673 689 6 ambrette-aquarium
674 690 6 unknown-dungeon
675 691 3 hoenn-pokemon-league
676 692 3 team-aqua-hideout
677 693 3 sea-mauville
678 694 3 team-magma-hideout
679 695 3 battle-resort
680 696 3 ss-tidal
681 697 3 mirage-forest
682 698 3 mirage-cave
683 699 3 mirage-mountain
684 700 3 trackless-forest
685 701 3 pathless-plain
686 702 3 nameless-cavern
687 703 3 fabled-cave
688 704 3 gnarled-den
689 705 3 crescent-isle
690 706 3 secret-islet
691 707 3 soaring-in-the-sky
692 708 3 secret-shore
693 709 3 secret-meadow
694 710 7 alola-route-1--hauoli-outskirts
695 711 7 alola-route-1
696 712 7 alola-route-3
697 713 7 alola-route-2
698 714 7 kalae-bay
699 715 7 melemele-sea
700 716 7 hauoli-city--beachfront
701 717 7 hauoli-city--shopping-district
702 718 7 hauoli-city--marina
703 719 7 iki-town
704 720 7 mahalo-trail
705 721 7 mahalo-trail--plank-bridge
706 722 7 ruins-of-conflict
707 723 7 ten-carat-hill
708 724 7 ten-carat-hill--farthest-hollow
709 725 7 hauoli-cemetery
710 726 7 melemele-meadow
711 727 7 seaward-cave
712 728 7 berry-fields
713 729 7 verdant-cavern--trial-site
714 730 7 verdant-cavern--totems-den
715 731 7 alola-route-4
716 732 7 alola-route-5
717 733 7 alola-route-6
718 734 7 alola-route-7
719 735 7 alola-route-8
720 736 7 alola-route-9
721 737 7 hano-grand-resort
722 738 7 hano-beach
723 739 7 akala-meadow
724 740 7 paniola-town
725 741 7 heahea-city
726 742 7 konikoni-city
727 743 7 royal-avenue
728 744 7 memorial-hill
729 745 7 paniola-ranch
730 746 7 wela-volcano-park
731 747 7 wela-volcano-park--totems-den
732 748 7 brooklet-hill
733 749 7 brooklet-hill--totems-den
734 750 7 lush-jungle
735 751 7 ruins-of-life
736 752 7 akala-outskirts
737 753 7 digletts-tunnel
738 754 7 battle-royal-dome
739 755 7 alola-route-10
740 756 7 alola-route-11
741 757 7 secluded-shore
742 758 7 alola-route-13
743 759 7 tapu-village
744 760 7 alola-route-15
745 761 7 alola-route-16
746 762 7 alola-route-17
747 763 7 alola-route-12
748 764 7 haina-desert
749 765 7 alola-route-14
750 766 7 ulaula-meadow
751 767 7 po-town
752 768 7 malie-city
753 769 7 malie-garden
754 770 7 mount-hokulani
755 771 7 blush-mountain
756 772 7 ruins-of-abundance
757 773 7 lake-of-the-sunne
758 774 7 lake-of-the-moone
759 775 7 mount-lanakila
760 776 7 shady-house
761 777 7 thrifty-megamart--abandoned-site
762 778 7 hokulani-observatory
763 779 7 alola-pokemon-league
764 780 7 poni-meadow
765 781 7 poni-wilds
766 782 7 ancient-poni-path
767 783 7 poni-breaker-coast
768 784 7 poni-grove
769 785 7 poni-plains
770 786 7 poni-coast
771 787 7 poni-gauntlet
772 788 7 seafolk-village
773 789 7 vast-poni-canyon
774 790 7 altar-of-the-sunne
775 791 7 altar-of-the-moone
776 792 7 ruins-of-hope
777 793 7 resolution-cave
778 794 7 exeggutor-island
779 795 7 battle-tree
780 796 7 aether-paradise
781 797 7 ultra-space
782 798 7 malie-city--outer-cape

View file

@ -210,7 +210,10 @@ def load(session, tables=[], directory=None, drop_tables=False, verbose=False, s
try:
csvpath = "%s/%s.csv" % (directory, table_name)
csvfile = open(csvpath, 'r')
if six.PY2:
csvfile = open(csvpath, 'r')
else:
csvfile = open(csvpath, 'r', encoding="utf8")
except IOError:
# File doesn't exist; don't load anything!
print_done('missing?')
@ -416,7 +419,7 @@ def dump(session, tables=[], directory=None, verbose=False, langs=None):
# CSV module only works with bytes on 2 and only works with text on 3!
if six.PY3:
writer = csv.writer(open(filename, 'w', newline=''), lineterminator='\n')
writer = csv.writer(open(filename, 'w', newline='', encoding="utf8"), lineterminator='\n')
columns = [col.name for col in table.columns]
else:
writer = csv.writer(open(filename, 'wb'), lineterminator='\n')

View file

@ -1103,7 +1103,7 @@ class Location(TableBase):
doc=u"A numeric ID")
region_id = Column(Integer, ForeignKey('regions.id'),
doc=u"ID of the region this location is in")
identifier = Column(Unicode(79), nullable=False,
identifier = Column(Unicode(79), nullable=False, unique=True,
doc=u"An identifier",
info=dict(format='identifier'))
@ -1112,6 +1112,11 @@ create_translation_table('location_names', Location, 'names',
name = Column(Unicode(79), nullable=False, index=True,
doc=u"The name",
info=dict(format='plaintext', official=True)),
subtitle = Column(Unicode(79), nullable=True, index=False,
doc=u"""A subtitle for the location, if any.
This may be an alternate name for the locaton, as in the Kalos routes,
or the name of a subarea of the location, as in Alola.""",
info=dict(format='plaintext', official=True)),
)
class LocationArea(TableBase):
@ -1128,6 +1133,11 @@ class LocationArea(TableBase):
doc=u"An identifier",
info=dict(format='identifier'))
__table_args__ = (
UniqueConstraint(location_id, identifier),
{},
)
create_translation_table('location_area_prose', LocationArea, 'prose',
relation_lazy='joined',
name = Column(Unicode(79), nullable=True, index=True,

View file

@ -262,11 +262,15 @@ class Translations(object):
def reader_for_class(self, cls, reader_class=csv.reader):
tablename = cls.__table__.name
csvpath = os.path.join(self.csv_directory, tablename + '.csv')
return reader_class(open(csvpath, 'r'), lineterminator='\n')
if six.PY2:
read = open(csvpath, 'r')
else:
read = open(csvpath, 'r', encoding='utf-8')
return reader_class(read, lineterminator='\n')
def writer_for_lang(self, lang):
csvpath = os.path.join(self.translation_directory, '%s.csv' % lang)
return csv.writer(io.open(csvpath, 'w', newline=''), lineterminator='\n')
return csv.writer(io.open(csvpath, 'w', newline='', encoding="utf8"), lineterminator='\n')
def yield_source_messages(self, language_id=None):
"""Yield all messages from source CSV files
@ -307,7 +311,10 @@ class Translations(object):
"""
path = os.path.join(self.csv_directory, 'translations', '%s.csv' % lang)
try:
file = open(path, 'r')
if six.PY2:
file = open(path, 'r')
else:
file = open(path, 'r', encoding="utf8")
except IOError:
return ()
return yield_translation_csv_messages(file)

View file

@ -14,11 +14,12 @@ from pokedex import defaults
def main(junk, *argv):
if len(argv) <= 0:
command_help()
return
parser = create_parser()
if len(argv) <= 0:
parser.print_help()
sys.exit()
args = parser.parse_args(argv)
args.func(parser, args)
@ -62,7 +63,7 @@ def create_parser():
parents=[common_parser],
)
cmds = parser.add_subparsers(title='Commands')
cmds = parser.add_subparsers(title='commands', metavar='<command>', help='commands')
cmd_help = cmds.add_parser(
'help', help=u'Display this message',
parents=[common_parser])

View file

@ -107,11 +107,11 @@ class SaveFilePokemon(object):
self._pokemon = session.query(tables.Pokemon).get(st.national_id)
self._pokemon_form = session.query(tables.PokemonForm) \
.with_parent(self._pokemon) \
.filter_by(name=st.alternate_form) \
.filter_by(form_identifier=st.alternate_form) \
.one()
self._ability = self._session.query(tables.Ability).get(st.ability_id)
growth_rate = self._pokemon.evolution_chain.growth_rate
growth_rate = self._pokemon.species.growth_rate
self._experience_rung = session.query(tables.Experience) \
.filter(tables.Experience.growth_rate == growth_rate) \
.filter(tables.Experience.experience <= st.exp) \

View file

@ -1,6 +1,8 @@
import pytest
parametrize = pytest.mark.parametrize
import re
from sqlalchemy.orm import aliased, joinedload, lazyload
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import func
@ -93,3 +95,22 @@ def test_default_forms(session):
pytest.fail("species %s has no default pokemon" % species.name)
elif num_default_pokemon > 1:
pytest.fail("species %s has %d default pokemon" % (species.name, num_default_pokemon))
ROUTE_RE = re.compile(u'route-\\d+')
def test_location_identifiers(session):
"""Check that location identifiers for some common locations are prefixed
with the region name, ala kalos-route-2"""
q = session.query(tables.Location)
q = q.join(tables.Region)
q = q.options(lazyload('*'))
for loc in q:
if (loc.identifier in [u'victory-road', u'pokemon-league', u'safari-zone']
or ROUTE_RE.match(loc.identifier)):
if loc.region:
region = loc.region.identifier.lower()
suggested_identifier = region + "-" + loc.identifier
pytest.fail("location %d: identifier %s should be prefixed with its region (e.g. %s)" % (loc.id, loc.identifier, suggested_identifier))
else:
pytest.fail("location %d: identifier %s should be prefixed with its region" % (loc.id, loc.identifier))

View file

@ -197,9 +197,11 @@ def test_texts(cls):
pytest.fail("%s: description mentions English" % column)
# If there's more than one text column in a translation table,
# they have to be nullable, to support missing translations
# Exception: the 'name' column may be required, if none of the other
# columns make sense without it
if hasattr(cls, 'local_language') and len(text_columns) > 1:
for column in text_columns:
assert column.nullable
assert column.nullable or column.name == 'name'
@parametrize('table', tables.mapped_classes)
def test_identifiers_with_names(table):

View file

@ -0,0 +1,104 @@
#!/usr/bin/env python2
# encoding: utf-8
# Adds locations to the database from the text dump.
#
# Usage: python add-oras-locations.py | psql pokedex
import os
import re
import io
def make_identifier(name):
"""Make a string safe to use as an identifier.
Valid characters are lowercase alphanumerics and "-". This function may
raise ValueError if it can't come up with a suitable identifier.
This function is useful for scripts which add things with names.
"""
if isinstance(name, bytes):
identifier = name.decode('utf-8')
else:
identifier = name
identifier = identifier.lower()
identifier = identifier.replace(u'+', u' plus ')
identifier = re.sub(u'[ _]+', u'-', identifier)
identifier = re.sub(u"['./;(),:]", u'', identifier)
identifier = identifier.replace(u'é', u'e')
if identifier == '???':
identifier = 'inside-of-truck'
if not identifier.replace(u"-", u"").isalnum():
raise ValueError(identifier)
return identifier
ROOT = os.path.expanduser("~/xy/orips/text")
en = io.open(os.path.join(ROOT, 'en/90'), encoding='utf-8')
lang_idents = {
'ja-kana': 'ja-Hrkt',
'ja-kanji': 'ja',
}
foreign = []
for lang in 'ja-kana', 'ja-kanji', 'en', 'fr', 'it', 'de', 'es', 'ko':
f = io.open(os.path.join(ROOT, lang, '90'), encoding='utf-8')
foreign.append((lang_idents.get(lang, lang), f))
REGION_ID = 3
GENERATION_ID = 6
START_LINE = 170 # locations before this line were from X/Y
import pokedex.db
import pokedex.db.tables as t
session = pokedex.db.connect("postgresql:///pokedex")
existing_location_ids = set(x for x, in session.query(t.Location.identifier).all())
#print(existing_location_ids)
print("BEGIN;")
print("SELECT setval('locations_id_seq', max(id)) FROM locations;")
for i, name in enumerate(en):
foreign_names = [(lang, next(iter).strip()) for lang, iter in foreign]
if i == 0:
continue
if i < START_LINE:
continue
if name == '\n':
continue
try:
ident = make_identifier(name.strip())
except ValueError:
continue
if ident == 'safari-zone':
ident = 'hoenn-safari-zone'
elif ident == 'victory-road':
ident = 'hoenn-victory-road'
elif ident == 'pokemon-league':
ident = 'hoenn-pokemon-league'
elif ident.startswith("route-"):
ident = 'hoenn-' + ident
print("\echo '%s'" % ident)
if ident in ('mystery-zone', 'faraway-place'):
## standard locations
pass
elif ident in existing_location_ids:
## location already exists from R/S,
## so keep the existing location and just replace the names
print("""DELETE FROM location_names WHERE location_id = (SELECT id FROM locations where identifier = '%s');""" % ident)
else:
## new location
print("""INSERT INTO locations (identifier, region_id) VALUES ('%s', %s) RETURNING id;""" % (ident, REGION_ID))
for lang, name in foreign_names:
print("""INSERT INTO location_names (location_id, local_language_id, name) SELECT loc.id, lang.id, '%s' FROM locations loc, languages lang WHERE loc.identifier = '%s' AND (loc.region_id is NULL OR loc.region_id = %d) AND lang.identifier = '%s';""" % (name.encode("utf-8"), ident.encode("utf-8"), REGION_ID, lang))
print("""INSERT INTO location_game_indices (location_id, generation_id, game_index) SELECT id, %s, %s FROM locations WHERE identifier='%s' AND (region_id is NULL OR region_id = %d) ON CONFLICT DO NOTHING;""" % (GENERATION_ID, i, ident.encode("utf-8"), REGION_ID))
#for pokemon_id, location_identifier in (462, 'kalos-route-13'), (470, 'kalos-route-20'), (471, 'frost-cavern'), (476, 'kalos-route-13'):
# print("UPDATE pokemon_evolution SET location_id = (SELECT id FROM locations WHERE identifier = '%s') WHERE location_id is NULL AND evolved_species_id = %d;" % (location_identifier, pokemon_id))
print("COMMIT;")

108
scripts/add-sm-locations.py Normal file
View file

@ -0,0 +1,108 @@
# encoding: utf-8
# Adds locations to the database from the text dump.
#
# Usage: python add-sm-locations.py | psql pokedex
from __future__ import unicode_literals, print_function
import io
import os
import re
import sys
def make_identifier(name):
"""Make a string safe to use as an identifier.
Valid characters are lowercase alphanumerics and "-". This function may
raise ValueError if it can't come up with a suitable identifier.
This function is useful for scripts which add things with names.
"""
if isinstance(name, bytes):
identifier = name.decode('utf-8')
else:
identifier = name
identifier = identifier.lower()
identifier = identifier.replace(u'+', u' plus ')
identifier = re.sub(u'[ _]+', u'-', identifier)
identifier = re.sub(u"['./;(),:]", u'', identifier)
identifier = identifier.replace(u'é', u'e')
if not identifier.replace(u"-", u"").isalnum():
raise ValueError(identifier)
return identifier
ROOT = os.path.expanduser("~/hacks/sm-encounters/textrip/text")
GENERATION_ID = 7
REGION_ID = 7
lang_idents = {
'ja-kana': 'ja-Hrkt',
'ja-kanji': 'ja',
}
foreign = []
for lang in 'ja-kana', 'ja-kanji', 'en', 'fr', 'it', 'de', 'es', 'ko', 'zh-Hans', 'zh-Hant':
with io.open(os.path.join(ROOT, lang, '67'), encoding="utf-8") as f:
names = []
while True:
name = f.readline()
subtitle = f.readline()
if not name:
break
names.append((name.strip(), subtitle.strip()))
foreign.append((lang_idents.get(lang, lang), names))
print("BEGIN;")
#print("UPDATE pokemon_evolution SET location_id = NULL WHERE location_id in (SELECT id FROM locations WHERE region_id = 6);")
print("DELETE FROM location_game_indices WHERE generation_id = %d;" % GENERATION_ID)
print("DELETE FROM location_names WHERE location_id IN (SELECT id FROM locations WHERE region_id = %d);" % REGION_ID)
print("DELETE FROM locations WHERE region_id=%d;" % REGION_ID)
print("SELECT setval('locations_id_seq', max(id)) FROM locations;")
en = foreign[2][1]
for i, (name, subtitle) in enumerate(en):
game_index = i * 2
foreign_names = [(lang, names[i]) for lang, names in foreign]
if i == 0:
continue
if name == '\n':
continue
try:
ident = make_identifier(name.strip())
except ValueError:
print(("bad location: %s" % name).encode("utf-8"), file=sys.stderr)
continue
if ident.startswith('route-'):
ident = 'alola-' + ident
elif ident == 'pokemon-league':
ident = 'alola-pokemon-league'
if subtitle:
try:
subident = make_identifier(subtitle.strip())
except ValueError:
print(("bad location: %s %s" % (name, subtitle)).encode("utf-8"), file=sys.stderr)
continue
ident = ident + "--" + subident
print("\echo '%s'" % ident)
if ident in ('mystery-zone', 'faraway-place'):
# standard locations
pass
elif ident == 'hano-grand-resort' and game_index == 102:
# I have no idea why where are two "Hano Grand Resort" locations.
# I think this one is unused
pass
else:
print("""INSERT INTO locations (identifier, region_id) VALUES ('%s', %s) RETURNING id;""" % (ident, REGION_ID))
for lang, (name, subtitle) in foreign_names:
print(("""INSERT INTO location_names (location_id, local_language_id, name, subtitle) SELECT loc.id, lang.id, '%s', '%s' FROM locations loc, languages lang WHERE loc.identifier = '%s' AND (loc.region_id is NULL OR loc.region_id = %d) AND lang.identifier = '%s';""" % (name, subtitle, ident, REGION_ID, lang)).encode("utf-8"))
print(("""INSERT INTO location_game_indices (location_id, generation_id, game_index) SELECT id, %s, %s FROM locations WHERE identifier='%s' AND (region_id is NULL OR region_id = %d);""" % (GENERATION_ID, game_index, ident, REGION_ID)).encode("utf-8"))
#for pokemon_id, location_identifier in (462, 'kalos-route-13'), (470, 'kalos-route-20'), (471, 'frost-cavern'), (476, 'kalos-route-13'):
# print("UPDATE pokemon_evolution SET location_id = (SELECT id FROM locations WHERE identifier = '%s') WHERE location_id is NULL AND evolved_species_id = %d;" % (location_identifier, pokemon_id))
print("COMMIT;")