-
Notifications
You must be signed in to change notification settings - Fork 33
/
fix_locations.py
228 lines (214 loc) · 5.71 KB
/
fix_locations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import json
usa_states = {
'Alabama': 'AL',
'Alaska': 'AK',
'Arizona': 'AZ',
'Arkansas': 'AR',
'California': 'CA',
'Colorado': 'CO',
'Connecticut': 'CT',
'Delaware': 'DE',
'Florida': 'FL',
'Georgia': 'GA',
'Hawaii': 'HA',
'Idaho': 'ID',
'Illinois': 'IL',
'Indiana': 'IN',
'Iowa': 'IA',
'Kansas': 'KS',
'Kentucky': 'KY',
'Louisiana': 'LA',
'Maine': 'ME',
'Maryland': 'MD',
'Massachusetts': 'MA',
'Michigan': 'MI',
'Minnesota': 'MN',
'Mississippi': 'MS',
'Missouri': 'MO',
'Montana': 'MT',
'Nebraska': 'NE',
'Nevada': 'NV',
'New Hampshire': 'NH',
'New Jersey': 'NJ',
'New Mexico': 'NM',
'New York': 'NY',
'North Carolina': 'NC',
'North Dakota': 'ND',
'Ohio': 'OH',
'Oklahoma': 'OK',
'Oregon': 'OR',
'Rhode Island': 'RI',
'Pennsylvania': 'PA',
'South Carolina': 'SC',
'South Dakota': 'SD',
'Tennessee': 'TN',
'Texas': 'TX',
'Utah': 'UT',
'Vermont': 'VT',
'Virginia': 'VA',
'Washington': 'WA',
'District of Columbia': 'DC',
'West Virginia': 'WV',
'Wisconsin': 'WI',
'Wyoming': 'WY',
}
canada_states = {
'Alberta': 'AB',
'British Columbia': 'BC',
'Manitoba': 'MB',
'New Brunswick': 'NB',
'Newfoundland and Labrador': 'NL',
'Nova Scotia': 'NS',
'Ontario': 'ON',
'Prince Edward Island': 'PE',
'Quebec': 'QC',
'Saskatchewan': 'SK',
}
countries = [
'Australia',
'Austria',
'Belarus',
'Belgium',
'Brazil',
'Canada',
'Chile',
'Croatia',
'Czech Republic',
'Denmark',
'England',
'Finland',
'France',
'Germany',
'Greece',
'Hungary',
'Iceland',
'Ireland',
'Italy',
'Japan',
'Lithuania',
'Mexico',
'Netherlands',
'New Zealand',
'Norway',
'Online',
'Philippines',
'Poland',
'Portugal',
'Russia',
'Scotland',
'Serbia',
'Singapore',
'Slovakia',
'South Africa',
'Spain',
'Sweden',
'Switzerland',
'USA',
'United Kingdom',
'Wales',
]
country_aliases = {
'United States': 'USA',
'Slovak Republic': 'Slovakia',
'South Australia': 'Australia',
'Russian Federation': 'Russia',
'Belorussia': 'Belarus',
'Online -- Lackey': 'Online',
}
fixes = {
'D.C.': {
'Washington': ['Washington (DC)', 'USA'],
},
'Victoria': {
'Melbourne': ['Melbourne', 'Australia'],
},
'Modena': {
'Italy': ['Modena', 'Italy'],
},
'United Kingdom': {
'Leeds': ['Leeds', 'England'],
'Liverpool': ['Liverpool', 'England'],
'Newcastle Upon Tyne': ['Newcastle upon Tyne', 'England'],
},
'Philadelphia': ['Philadelphia (PA)', 'USA'],
}
cities_fixes = {
'Bad Naumheim': 'Bad Nauheim',
'Bad\u00eda del Vall\u00e9s': 'Badia del Vallès',
'Badia del Vall\u00e8s': 'Badia del Vallès',
'Bailleau le Pin': 'Bailleau-le-Pin',
'Barceloma': 'Barcelona',
'Bourg La Reine': 'Bourg-la-Reine',
'Bourg la Reine': 'Bourg-la-Reine',
'Bruxelles': 'Brussels',
'Burton on Trent': 'Burton upon Trent',
'Burton-on-Trent': 'Burton upon Trent',
'Bystricka': 'Bystrička',
'Cincinatti (OH)': 'Cincinnati (OH)',
'Columbus Convention Centre (OH)': 'Columbus (OH)',
'Duboicze Cerkiewne': 'Dubicze Cerkiewne',
'Espoo (Helsinki)': 'Espoo',
'Gatineau': 'Gatineau (QC)',
'Gen\u00e8ve': 'Geneva',
'Genova': 'Genoa',
'Goteborg': 'Gothenburg',
'Hradec Kr\u00e1lov\u00e9': 'Hradec Králové',
'Hradec Kralove': 'Hradec Králové',
'Katalinpuszta-Szendehely': 'Katalinpuszta',
'Kecskemet': 'Kecskemét',
'Lisboa': 'Lisbon',
'Massa Carrara': 'Massa',
'Matar\u00f3': 'Mataró',
'Mataro': 'Mataró',
'Milano': 'Milan',
'Moskow': 'Moscow',
'Newcastle (New South Wales)': 'Newcastle',
'Palma de Malloca': 'Palma de Mallorca',
'Palma de Malorca': 'Palma de Mallorca',
'Pozna\u0144': 'Poznań',
'Poznan': 'Poznań',
'Praha': 'Prague',
'S\u00e3o Paulo': 'São Paulo',
'Sa\u00f5 Paulo': 'São Paulo',
'Toluca de Lerdo': 'Toluca',
'Veszpr\u00e9m': 'Veszprém',
'Veszprem': 'Veszprém',
'Warszawa': 'Warsaw',
'Wheatridge (CO)': 'Wheat Ridge (CO)',
}
with open("twda.json", "r") as twda_file, open("locations.json", "w") as locations_file:
twda = json.load(twda_file)
for deck in twda:
location = deck['place'].split(', ')
country = location[-1]
city = location[-2] if len(location) > 1 else None
other = location[-3] if len(location) > 2 else None
if country in usa_states.keys():
state = country
city = f"{city} ({usa_states[state]})"
country = 'USA'
elif country in canada_states.keys():
state = country
city = f"{city} ({canada_states[state]})"
country = 'Canada'
elif country in country_aliases.keys():
country = country_aliases[country]
elif country in fixes.keys():
if city:
[city, country] = fixes[country][city]
else:
[city, country] = fixes[country]
elif country not in countries:
print('WARNING! COUNTRY NOT IN LIST:', deck['id'], deck['place'])
if city in cities_fixes.keys():
city = cities_fixes[city]
place = f""
if other:
place += f"{other}, "
if city:
place += f"{city}, "
place += f"{country}\n"
with open(f"decks/{deck['id']}.txt", "r") as input_file, open(f"decks_fixed/{deck['id']}.txt", "w") as output_file:
data = input_file.readlines()
data[1] = place
output_file.writelines(data)