Great Item Effect Rewrite, part 2: up through berries. #247
[zzz-pokedex.git] / scripts / add-bw-locations.py
1 #!/usr/bin/env python2
2
3 from codecs import open
4
5 from pokedex.db import connect, identifier_from_name
6 from pokedex.db.tables import Language
7 from pokedex.db.tables import Location, LocationGameIndex
8
9 session = connect()
10
11 en = session.query(Language).filter_by(identifier='en').one() # English
12 ja = session.query(Language).filter_by(identifier='ja').one() # Japanese
13
14 with open("bw-location-names-en", "r", "utf-8") as f:
15 en_names = [line.rstrip("\n") for line in f]
16 with open("bw-location-names-kanji", "r", "utf-8") as f:
17 ja_names = [line.rstrip("\n") for line in f]
18
19 locations = {}
20 for i, name in enumerate(zip(en_names, ja_names)):
21 if i == 0:
22 continue
23
24 en_name, ja_name = name
25 if not en_name:
26 continue
27
28 if name in locations:
29 loc = locations[name]
30 else:
31 loc = Location()
32 if en_name:
33 loc.name_map[en] = en_name
34 if ja_name:
35 loc.name_map[ja] = ja_name
36 loc.region_id = 5 # Unova
37 loc.identifier = identifier_from_name(en_name)
38
39 locations[name] = loc
40
41 lgi = LocationGameIndex()
42 lgi.location = loc
43 lgi.generation_id = 5 # Gen 5
44 lgi.game_index = i
45
46 session.add(loc)
47 session.add(lgi)
48
49 session.commit()