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:
commit
496b5098de
15 changed files with 4169 additions and 2115 deletions
|
@ -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
|
||||
|
|
|
@ -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,第七世代
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
|
@ -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
|
||||
|
|
|
File diff suppressed because it is too large
Load diff
|
@ -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
|
||||
|
|
|
|
@ -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')
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
|
|
104
scripts/add-oras-locations.py
Normal file
104
scripts/add-oras-locations.py
Normal 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
108
scripts/add-sm-locations.py
Normal 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;")
|
Loading…
Add table
Reference in a new issue