-
Notifications
You must be signed in to change notification settings - Fork 88
/
geoname2fips.py
executable file
·1320 lines (1225 loc) · 38.1 KB
/
geoname2fips.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# The MIT License (MIT)
#
# Copyright (c) 2019 Gianluigi Tiesi
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import re
import csv
import argparse
from typing import Pattern
# noinspection PyPackageRequirements
from unidecode import unidecode
from collections import defaultdict
# dataset from: https://github.com/datasets/fips-10-4
# with the help of: https://en.wikipedia.org/wiki/List_of_FIPS_region_codes
# FIPS 10-4 country codes to maxmind country names
FIPS_COUNTRIES = {
'AFGHANISTAN': 'AF',
'AKROTIRI SOVEREIGN BASE AREA': 'AX',
'ALBANIA': 'AL',
'ALGERIA': 'AG',
'AMERICAN SAMOA': 'AQ',
'ANDORRA': 'AN',
'ANGOLA': 'AO',
'ANGUILLA': 'AV',
'ANTARCTICA': 'AY',
'ANTIGUA AND BARBUDA': 'AC',
'ARGENTINA': 'AR',
'ARMENIA': 'AM',
'ARUBA': 'AA',
'ASHMORE AND CARTIER ISLANDS': 'AT',
'AUSTRALIA': 'AS',
'AUSTRIA': 'AU',
'AZERBAIJAN': 'AJ',
'BAHAMAS': 'BF',
'BAHRAIN': 'BA',
'BAKER ISLAND': 'FQ',
'BANGLADESH': 'BG',
'BARBADOS': 'BB',
'BASSAS DA INDIA': 'BS',
'BELARUS': 'BO',
'BELGIUM': 'BE',
'BELIZE': 'BH',
'BENIN': 'BN',
'BERMUDA': 'BD',
'BHUTAN': 'BT',
'BOLIVIA': 'BL',
'BOSNIA AND HERZEGOVINA': 'BK',
'BOTSWANA': 'BC',
'BOUVET ISLAND': 'BV',
'BRAZIL': 'BR',
'BRITISH INDIAN OCEAN TERRITORY': 'IO',
'BRITISH VIRGIN ISLANDS': 'VI',
'BRUNEI': 'BX',
'BULGARIA': 'BU',
'BURKINA FASO': 'UV',
'BURMA': 'BM',
'BURUNDI': 'BY',
'CABO VERDE': 'CV',
'CAMBODIA': 'CB',
'CAMEROON': 'CM',
'CANADA': 'CA',
'CAYMAN ISLANDS': 'CJ',
'CENTRAL AFRICAN REPUBLIC': 'CT',
'CHAD': 'CD',
'CHILE': 'CI',
'CHINA': 'CH',
'CHRISTMAS ISLAND': 'KT',
'CLIPPERTON ISLAND': 'IP',
'COCOS ISLANDS': 'CK',
'COLOMBIA': 'CO',
'COMOROS': 'CN',
'DR CONGO': 'CG', # renamed from 'CONGO' in GeoLite2-City-CSV_20200505
'COOK ISLANDS': 'CW',
'CORAL SEA ISLANDS': 'CR',
'COSTA RICA': 'CS',
'IVORY COAST': 'IV',
'CROATIA': 'HR',
'CUBA': 'CU',
'CYPRUS': 'CY',
'CZECHIA': 'EZ',
'EAST TIMOR': 'TT', # renamed from 'DEMOCRATIC REPUBLIC OF TIMOR LESTE' in GeoLite2-City-CSV_20200505
'DENMARK': 'DA',
'DHEKELIA SOVEREIGN BASE AREA': 'DX',
'DJIBOUTI': 'DJ',
'DOMINICA': 'DO',
'DOMINICAN REPUBLIC': 'DR',
'ECUADOR': 'EC',
'EGYPT': 'EG',
'EL SALVADOR': 'ES',
'EQUATORIAL GUINEA': 'EK',
'ERITREA': 'ER',
'ESTONIA': 'EN',
'ESWATINI': 'WZ',
'ETHIOPIA': 'ET',
'ETOROFU HABOMAI KUNASHIRI AND SHIKOTAN ISLANDS': 'PJ',
'EUROPA ISLAND': 'EU',
'FALKLAND ISLANDS': 'FK',
'FAROE ISLANDS': 'FO',
'FEDERATED STATES OF MICRONESIA': 'FM',
'FIJI': 'FJ',
'FINLAND': 'FI',
'FRANCE': 'FR',
'FRENCH GUIANA': 'FG',
'FRENCH POLYNESIA': 'FP',
'FRENCH SOUTHERN TERRITORIES': 'FS',
'GABON': 'GB',
'GAMBIA': 'GA',
'GEORGIA': 'GG',
'GERMANY': 'GM',
'GHANA': 'GH',
'GIBRALTAR': 'GI',
'GLORIOSO ISLANDS': 'GO',
'GREECE': 'GR',
'GREENLAND': 'GL',
'GRENADA': 'GJ',
'GUADELOUPE': 'GP',
'GUAM': 'GQ',
'GUATEMALA': 'GT',
'GUERNSEY': 'GK',
'GUINEA': 'GV',
'GUINEA BISSAU': 'PU',
'GUYANA': 'GY',
'HAITI': 'HA',
'HASHEMITE KINGDOM OF JORDAN': 'JO',
'HEARD ISLAND AND MCDONALD ISLANDS': 'HM',
'HONDURAS': 'HO',
'HONG KONG': 'HK',
'HOWLAND ISLAND': 'HQ',
'HUNGARY': 'HU',
'ICELAND': 'IC',
'INDIA': 'IN',
'INDONESIA': 'ID',
'IRAN': 'IR',
'IRAQ': 'IZ',
'IRELAND': 'EI',
'ISLE OF MAN': 'IM',
'ISRAEL': 'IS',
'ITALY': 'IT',
'JAMAICA': 'JM',
'JAPAN': 'JA',
'JARVIS ISLAND': 'DQ',
'JERSEY': 'JE',
'JOHNSTON ATOLL': 'JQ',
'JUAN DE NOVA ISLAND': 'JU',
'KAZAKHSTAN': 'KZ',
'KENYA': 'KE',
'KINGMAN REEF': 'KQ',
'KIRIBATI': 'KR',
'KOSOVO': 'KV',
'KUWAIT': 'KU',
'KYRGYZSTAN': 'KG',
'LAOS': 'LA',
'LATVIA': 'LG',
'LEBANON': 'LE',
'LESOTHO': 'LT',
'LIBERIA': 'LI',
'LIBYA': 'LY',
'LIECHTENSTEIN': 'LS',
'LUXEMBOURG': 'LU',
'MACAO': 'MC',
'NORTH MACEDONIA': 'MK', # before 2019 'MACEDONIA'
'MADAGASCAR': 'MA',
'MALAWI': 'MI',
'MALAYSIA': 'MY',
'MALDIVES': 'MV',
'MALI': 'ML',
'MALTA': 'MT',
'MARSHALL ISLANDS': 'RM',
'MARTINIQUE': 'MB',
'MAURITANIA': 'MR',
'MAURITIUS': 'MP',
'MAYOTTE': 'MF',
'MEXICO': 'MX',
'MIDWAY ISLANDS': 'MQ',
'MONACO': 'MN',
'MONGOLIA': 'MG',
'MONTENEGRO': 'MJ',
'MONTSERRAT': 'MH',
'MOROCCO': 'MO',
'MOZAMBIQUE': 'MZ',
'MYANMAR': 'MM',
'NAMIBIA': 'WA',
'NAURU': 'NR',
'NAVASSA ISLAND': 'BQ',
'NEPAL': 'NP',
'NETHERLANDS': 'NL',
'NETHERLANDS ANTILLES': 'NT',
'NEW CALEDONIA': 'NC',
'NEW ZEALAND': 'NZ',
'NICARAGUA': 'NU',
'NIGER': 'NG',
'NIGERIA': 'NI',
'NIUE': 'NE',
'NORFOLK ISLAND': 'NF',
'NORTH KOREA': 'KN',
'NORTHERN MARIANA ISLANDS': 'CQ',
'NORWAY': 'NO',
'OMAN': 'MU',
'PAKISTAN': 'PK',
'PALAU': 'PS',
'PALMYRA ATOLL': 'LQ',
'PANAMA': 'PM',
'PAPUA NEW GUINEA': 'PP',
'PARACEL ISLANDS': 'PF',
'PARAGUAY': 'PA',
'PERU': 'PE',
'PHILIPPINES': 'RP',
'PITCAIRN ISLANDS': 'PC',
'POLAND': 'PL',
'PORTUGAL': 'PO',
'PUERTO RICO': 'RQ',
'QATAR': 'QA',
'SOUTH KOREA': 'KS', # renamed from 'REPUBLIC OF KOREA' in GeoLite2-City-CSV_20200505
'REPUBLIC OF LITHUANIA': 'LH',
'REPUBLIC OF MOLDOVA': 'MD',
'CONGO REPUBLIC': 'CF', # renamed from 'REPUBLIC OF CONGO' in GeoLite2-City-CSV_20200505
'ROMANIA': 'RO',
'RUSSIA': 'RS',
'RWANDA': 'RW',
'REUNION': 'RE',
'SAINT BARTHELEMY': 'TB',
'SAINT HELENA': 'SH',
'SAINT LUCIA': 'ST',
'SAINT MARTIN': 'RN',
'SAINT PIERRE AND MIQUELON': 'SB',
'SAINT VINCENT AND GRENADINES': 'VC',
'SAMOA': 'WS',
'SAN MARINO': 'SM',
'SAUDI ARABIA': 'SA',
'SENEGAL': 'SG',
'SERBIA': 'RI',
'SEYCHELLES': 'SE',
'SIERRA LEONE': 'SL',
'SINGAPORE': 'SN',
'SLOVAKIA': 'LO',
'SLOVENIA': 'SI',
'SOLOMON ISLANDS': 'BP',
'SOMALIA': 'SO',
'SOUTH AFRICA': 'SF',
'SOUTH GEORGIA AND SOUTH SANDWICH ISLANDS': 'SX',
'SOUTH SUDAN': 'SS',
'SPAIN': 'SP',
'SPRATLY ISLANDS': 'PG',
'SRI LANKA': 'CE',
'ST KITTS AND NEVIS': 'SC',
'SUDAN': 'SU',
'SURINAME': 'NS',
'SVALBARD AND JAN MAYEN': 'SV',
'SWEDEN': 'SW',
'SWITZERLAND': 'SZ',
'SYRIA': 'SY',
'SAO TOME AND PRINCIPE': 'TP',
'TAIWAN': 'TW',
'TAJIKISTAN': 'TI',
'TANZANIA': 'TZ',
'THAILAND': 'TH',
'TOGO': 'TO',
'TOKELAU': 'TL',
'TONGA': 'TN',
'TRINIDAD AND TOBAGO': 'TD',
'TROMELIN ISLAND': 'TE',
'TUNISIA': 'TS',
'TURKEY': 'TU',
'TURKMENISTAN': 'TX',
'TURKS AND CAICOS ISLANDS': 'TK',
'TUVALU': 'TV',
'US VIRGIN ISLANDS': 'VQ',
'UGANDA': 'UG',
'UKRAINE': 'UP',
'UNDESIGNATED SOVEREIGNTY': 'UU',
'UNITED ARAB EMIRATES': 'AE',
'UNITED KINGDOM': 'UK',
'UNITED STATES': 'US',
'URUGUAY': 'UY',
'UZBEKISTAN': 'UZ',
'VANUATU': 'NH',
'VATICAN CITY': 'VT',
'VENEZUELA': 'VE',
'VIETNAM': 'VM',
'WAKE ISLAND': 'WQ',
'WALLIS AND FUTUNA': 'WF',
'WEST BANK': 'WE',
'WESTERN SAHARA': 'WI',
'YEMEN': 'YM',
'ZAMBIA': 'ZA',
'ZIMBABWE': 'ZI'
}
COUNTRY_IGNORE = (
# without FIPS 10-4 code
'ALAND',
'BONAIRE, SINT EUSTATIUS, AND SABA',
'CURACAO',
'SINT MAARTEN',
'US MINOR OUTLYING ISLANDS',
'PALESTINE', # WE? no entries on wikipedia
# empty in fips csv
'AMERICAN SAMOA',
'COOK ISLANDS',
'EAST TIMOR',
'FRENCH POLYNESIA',
'FRENCH SOUTHERN TERRITORIES',
'HONG KONG',
'MALTA',
'MARSHALL ISLANDS',
'MONTENEGRO',
'NEW CALEDONIA',
'NORTHERN MARIANA ISLANDS',
'SAINT PIERRE AND MIQUELON',
'SINGAPORE',
'SVALBARD AND JAN MAYEN',
'TOKELAU',
'TUVALU',
'US VIRGIN ISLANDS',
'WALLIS AND FUTUNA',
# missing in fips csv
'ISLE OF MAN',
'MYANMAR',
'SOUTH SUDAN',
# wip
'INDIA',
'INDONESIA',
'IRAN',
'ISRAEL',
'IVORY COAST',
'KAZAKHSTAN',
'KENYA',
'LAOS',
'LATVIA',
'LIBERIA',
'LIBYA',
'LUXEMBOURG',
'NORTH MACEDONIA',
'MALAWI',
'MAURITANIA',
'MEXICO',
'MONGOLIA',
'MOROCCO',
'MOZAMBIQUE',
'NAMIBIA',
'NEPAL',
'NIGERIA',
'NORTH KOREA',
'PAKISTAN',
'PAPUA NEW GUINEA',
'PARAGUAY',
'PHILIPPINES',
'POLAND',
'QATAR',
'CONGO REPUBLIC',
'SOUTH KOREA',
'REPUBLIC OF LITHUANIA',
'REPUBLIC OF MOLDOVA',
'RUSSIA',
'SAINT LUCIA',
'SAUDI ARABIA',
'SENEGAL',
'SERBIA',
'SLOVAKIA',
'SLOVENIA',
'SOMALIA',
'SOUTH AFRICA',
'SRI LANKA',
'SUDAN',
'SWITZERLAND',
'TANZANIA',
'THAILAND',
'TUNISIA',
'TURKMENISTAN',
'UGANDA',
'UKRAINE',
'UNITED KINGDOM',
'VIETNAM'
)
CITY_IGNORE = {
'AZERBAIJAN': ('AGHSU RAYON',),
'BAHAMAS': ('CENTRAL ABACO DISTRICT', 'EAST GRAND BAHAMA DISTRICT', 'HOPE TOWN DISTRICT', 'NORTH ELEUTHERA'),
'CZECHIA': ('CZECHIA',), # city?
'DR CONGO': ('BOENDE',),
'ESWATINI': ('ESWATINI',), # city?
}
REGION_IGNORE = {
'BAHAMAS': ('NORTH ANDROS DISTRICT', 'CENTRAL ANDROS DISTRICT', 'MOORES ISLAND DISTRICT', 'NORTH ABACO DISTRICT',
'GRAND CAY DISTRICT', 'SPANISH WELLS DISTRICT', 'EAST GRAND BAHAMA DISTRICT',
'WEST GRAND BAHAMA DISTRICT'),
'BAHRAIN': ('NORTHERN', 'SOUTHERN GOVERNORATE'),
'BOSNIA AND HERZEGOVINA': ('BRCKO',),
'BOTSWANA': ('CHOBE DISTRICT', 'JWANENG', 'LOBATSE'),
'BHUTAN': ('GASA', 'TRASHI YANGSTE'),
'BURKINA FASO': ('CASCADES REGION', 'CENTRE', 'CENTRE EST', 'CENTRE NORD', 'CENTRE OUEST', 'EST', 'HAUTS BASSINS',
'NORD', 'PLATEAU CENTRAL', 'SUD OUEST'),
'CAMBODIA': ('TBOUNG KHMUM',),
# since 2018
'CHILE': ('NUBLE',),
# since 2010
'CUBA': ('MAYABEQUE',),
'EGYPT': ('LUXOR',),
'FINLAND': ('CENTRAL FINLAND', 'NORTHERN OSTROBOTHNIA', 'SOUTHERN OSTROBOTHNIA', 'CENTRAL OSTROBOTHNIA',
'OSTROBOTHNIA', 'FINLAND PROPER', 'TAVASTIA PROPER', 'PIRKANMAA', 'KYMENLAAKSO', 'UUSIMAA',
'NORTH KARELIA', 'SATAKUNTA', 'SOUTHERN SAVONIA', 'PAIJANNE TAVASTIA', 'NORTHERN SAVO',
'SOUTH KARELIA', 'KAINUU'),
# since 2016
'FRANCE': ('NOUVELLE AQUITAINE', 'BOURGOGNE FRANCHE COMTE', 'HAUTS DE FRANCE', 'OCCITANIE', 'GRAND EST',
'AUVERGNE RHONE ALPES', 'NORMANDY'),
'GEORGIA': ('SAMTSKHE JAVAKHETI', 'GURIA', 'IMERETI', 'KAKHETI', 'KVEMO KARTLI',
'RACHA LECHKHUMI AND KVEMO SVANETI', 'SAMEGRELO AND ZEMO SVANETI', 'SHIDA KARTLI'),
'GREECE': ('NORTH AEGEAN', 'SOUTH AEGEAN', 'CENTRAL GREECE', 'WEST GREECE', 'CENTRAL MACEDONIA', 'WEST MACEDONIA',
'CRETE', 'EPIRUS', 'IONIAN ISLANDS', 'PELOPONNESE', 'MOUNT ATHOS'),
# since 2018
'GREENLAND': ('QEQERTALIK', 'AVANNAATA'),
'GRENADA': ('CARRIACOU AND PETITE MARTINIQUE',),
'IRELAND': ('LEINSTER', 'MUNSTER', 'CONNAUGHT', 'ULSTER'),
'MALDIVES': ('NORTHERN ARI ATOLL',),
'NEW ZEALAND': ('TASMAN',), # Tasman Region was not assigned a code for unknown reasons. (wikipedia)
'NORWAY': ('TRONDELAG',),
'OMAN': ('AL BATINAH NORTH GOVERNORATE', 'AL BATINAH SOUTH', 'NORTHEASTERN GOVERNORATE',
'SOUTHEASTERN GOVERNORATE'),
'TAIWAN': ('YUNLIN', 'NANTOU', 'CHIAYI', 'CHIAYI COUNTY', 'PENGHU COUNTY', 'HSINCHU COUNTY', 'CHANGHUA',
'TAICHUNG CITY', 'TAINAN', 'TAOYUAN', 'KEELUNG', 'YILAN', 'MIAOLI', 'KINMEN COUNTY', 'PINGTUNG',
'LIENCHIANG', 'HUALIEN', 'TAITUNG', 'HSINCHU', 'NEW TAIPEI'),
'TAJIKISTAN': ('DUSHANBE', 'GORNO BADAKHSHAN', 'REPUBLICAN SUBORDINATION'),
'TRINIDAD AND TOBAGO': ('SAN JUAN/LAVENTILLE', 'TUNAPUNA/PIARCO', 'PENAL/DEBE', 'POINT FORTIN',
'COUVA TABAQUITE TALPARO', 'DIEGO MARTIN', 'CHAGUANAS', 'SIPARIA', 'PRINCES TOWN',
'SANGRE GRANDE'),
'PANAMA': ('NGOEBE BUGLE', 'PANAMA OESTE', 'EMBERA WOUNAAN', 'GUNA YALA'),
# since 2017
'SIERRA LEONE': ('NORTH WEST',),
'SOLOMON ISLANDS': ('HONIARA',),
'SPAIN': ('CEUTA', 'MELILLA'),
'TONGA': ('EUA', 'NIUAS'),
# since 2004
'YEMEN': ('RAYMAH', 'SOQATRA'),
# since 2011
'ZAMBIA': ('MUCHINGA',)
}
REGION_REPLACE = {
'AE': {
'ABU ZABY': 'ABU DHABI',
'DUBAYY': 'DUBAI'
},
'AF': {
'KABOL': 'KABUL',
'KANDAHAR KANDAHAR': 'KANDAHAR'
},
'AG': {
'ALGER': 'ALGIERS',
'TAMANGHASSET': 'TAMANRASSET',
},
'AJ': {
'ABSERON': 'ABSHERON',
'BAKI': 'BAKU CITY',
'GANCA': 'GANJA CITY',
'NAXCIVAN': 'NAKHICHEVAN',
'YARDIMLI': 'YARDYMLI',
'SAKI': 'SHAKI CITY',
'SUMQAYIT': 'SUMQAYIT CITY',
},
'AL': {
'BERAT': 'BERATIT',
'DIBER': 'DIBRES',
'DURRES': 'DURRESIT',
'ELBASAN': 'ELBASANIT',
'FIER': 'FIERIT',
'TIRANE': 'TIRANA',
'GJIROKASTER': 'GJIROKASTRES',
'KORCE': 'KORCES',
'LEZHE': 'LEZHES',
'SHKODER': 'SHKODRES',
'VLORE': 'VLORES'
},
'AM': {
'LORRI': 'LORI'
},
'AO': {
'CUANDO CUBANGO': 'CUANDO COBANGO',
'CUANZA SUL': 'KWANZA SUL',
'LUNDA NORTE': 'LUANDA NORTE',
},
'AR': {
'TIERRA DEL FUEGO ANTARTIDA E ISLAS DEL ATLANTICO SUR': 'TIERRA DEL FUEGO'
},
'AU': {
'KARNTEN': 'CARINTHIA',
'NIEDEROSTERREICH': 'LOWER AUSTRIA',
'OBEROSTERREICH': 'UPPER AUSTRIA',
'STEIERMARK': 'STYRIA',
'TIROL': 'TYROL',
'WIEN': 'VIENNA'
},
'BA': {
'AL MUHARRAQ': 'MUHARRAQ',
'AL ASIMAH': 'MANAMA',
'AR RIFA WA AL MINTAQAH AL JANUBIYAH': 'AR RIFA'
},
'BC': {
'CENTRAL': 'CENTRAL DISTRICT',
'FRANCISTOWN': 'CENTRAL',
'SOUTH EAST': 'GABORONE',
'SOUTHERN': 'NGWAKETSI',
},
'BD': {
'HAMILTON': 'HAMILTON CITY',
},
'BE': {
'BRABANT WALLON': 'WALLONIA',
'BRUSSELS HOOFDSTEDELIJK GEWEST/REGION DE BRUXELLES CAPITALE': 'BRUSSELS CAPITAL',
'VLAAMS BRABANT': 'FLANDERS'
},
'BF': {
# 'FREEPORT': 'CITY OF FREEPORT',
'NICHOLLSTOWN AND BERRY ISLANDS': 'BERRY ISLANDS',
'SANDY POINT': 'SOUTH ABACO'
},
'BG': {
'RANGPUR DIVISION': 'RAJSHAHI',
'MYMENSINGH DIVISION': 'DHAKA'
},
'BK': {
'FEDERATION OF BOSNIA AND HERZEGOVINA': 'FEDERATION OF B&H',
'REPUBLICA SRPSKA': 'REPUBLIKA SRPSKA'
},
'BO': {
'BRESTSKAYA VOBLASTS': 'BREST',
'HOMYELSKAYA VOBLASTS': 'GOMEL',
'HRODZYENSKAYA VOBLASTS': 'GRODNENSKAYA',
'MAHILYOWSKAYA VOBLASTS': 'MOGILEV',
'MINSKAYA VOBLASTS': 'MINSK CITY',
'VITSYEBSKAYA VOBLASTS': 'VITEBSK'
},
'BP': {
'MAKIRA': 'MAKIRA ULAWA'
},
'BR': {
'DISTRITO FEDERAL': 'FEDERAL DISTRICT'
},
'BT': {
'CHHUKHA': 'CHUKHA',
'CHIRANG': 'TSIRANG',
'DAGA': 'DAGANA',
'GEYLEGPHUG': 'SARPANG',
'HA': 'HAA',
'LHUNTSHI': 'LHUNTSE',
'PEMAGATSEL': 'PEMAGATSHEL',
'SAMDRUP': 'SAMDRUP JONGKHAR',
'TASHIGANG': 'TRASHIGANG',
'TONGSA': 'TRONGSA',
'WANGDI PHODRANG': 'WANGDUE PHODRANG'
},
'BU': {
'KHASKOVO': 'HASKOVO',
'KURDZHALI': 'KARDZHALI',
'SOFIYA': 'SOFIA',
'SOFIYA GRAD': 'SOFIA CAPITAL',
'TURGOVISHTE': 'TARGOVISHTE',
'VELIKO TURNOVO': 'VELIKO TARNOVO'
},
'CA': {
'YUKON TERRITORY': 'YUKON'
},
'CB': {
'BANTEAY MEAN CHEAY': 'BANTEAY MEANCHEY',
'BATDAMBANG': 'BATTAMBANG',
'KAMPONG SPOE': 'KAMPONG SPEU',
'KAMPONG THUM': 'KAMPONG THOM',
'KAOH KONG': 'KOH KONG',
'KRACHEH': 'KRATIE',
'KEB': 'KEP',
'MONDOL KIRI': 'MONDOLKIRI',
'PHNUM PENH': 'PHNOM PENH',
'POUTHISAT': 'PURSAT',
'PREAH SEIHANU': 'PREAH SIHANOUK',
'ROTANAH KIRI': 'RATANAKIRI',
'SIEM REAB': 'SIEM REAP',
'STOENG TRENG': 'STUNG TRENG',
'TAKEV': 'TAKEO',
'OTDAR MEAN CHEAY': 'OTAR MEANCHEY'
},
'CD': {
'OUADDAI': 'OUADAI'
},
'CG': {
'SUD KIVU': 'SOUTH KIVU',
'KINSHASA': 'KINSHASA CITY'
},
'CH': {
'NEI MONGOL INNER MONGOLIA': 'INNER MONGOLIA AUTONOMOUS REGION',
'XIZANG TIBET': 'TIBET',
'NINGXIA NINGXIA': 'NINGXIA HUI AUTONOMOUS REGION'
},
'CI': {
'BIO BIO': 'BIOBIO',
'AISEN DEL GENERAL CARLOS IBANEZ DEL CAMPO': 'AYSEN',
'REGION METROPOLITANA': 'SANTIAGO METROPOLITAN',
'LIBERTADOR GENERAL BERNARDO OHIGGINS': 'OHIGGINS REGION',
'MAGALLANES Y DE LA ANTARTICA CHILENA': 'REGION OF MAGALLANES'
},
'CM': {
'OUEST WEST': 'WEST REGION',
'NORD OUEST NORTH WEST': 'NORTH WEST REGION',
'SUD OUEST SOUTH WEST': 'SOUTH WEST REGION',
'SUD SOUTH': 'SOUTH'
},
'CN': {
'ANJOUAN': 'NDZUWANI'
},
'CO': {
'DISTRITO CAPITAL': 'BOGOTA DC'
},
'CT': {
'NANA GREBINGUI': 'NANA GREBIZI'
},
'CU': {
'ISLA DE LA JUVENTUD': 'MUNICIPIO ESPECIAL ISLA DE LA JUVENTUD',
'LA HABANA': 'HAVANA'
},
'CV': {
'CAPE VERDE': 'CABO VERDE',
'RIBEIRA GRANDE': 'RIBEIRA GRANDE DE SANTIAGO',
'SANTA CRUZ': 'SAO LOURENCO DOS ORGAOS', # since 2005
},
'CY': {
'FAMAGUSTA': 'AMMOCHOSTOS',
'PAPHOS': 'PAFOS',
'LARNACA': 'LARNAKA',
'KYRENIA': 'KERYNEIA'
},
'DA': {
'SYDDANMARK': 'SOUTH DENMARK',
'NORDJYLLAND': 'NORTH DENMARK',
'MIDTJYLLEN': 'CENTRAL JUTLAND',
'HOVEDSTADEN': 'CAPITAL REGION',
'SJAELLAND': 'ZEALAND'
},
'DJ': {
'TADJOURA': 'TADJOURAH'
},
'DR': {
'DISTRITO NACIONAL': 'NACIONAL',
'BAHORUCO': 'BAORUCO',
'SALCEDO': 'HERMANAS MIRABAL'
},
'EC': {
'ORELLANA': 'FRANCISCO DE ORELLANA'
},
'EG': {
'AL JIZAH': 'GIZA',
'ASH SHARQIYAH': 'SHARQIA',
'AD DAQAHLIYAH': 'DAKAHLIA',
'AL QALYUBIYAH': 'QALYUBIA',
'AL GHARBIYAH': 'GHARBIA',
'AL FAYYUM': 'FAIYUM',
'AL ISKANDARIYAH': 'ALEXANDRIA',
'AL QAHIRAH': 'CAIRO GOVERNORATE',
'QINA': 'QENA',
'AL MINUFIYAH': 'MONUFIA',
'KAFR ASH SHAYKH': 'KAFR EL SHEIKH',
'AL BUHAYRAH': 'BEHEIRA',
'BANI SUWAYF': 'BENI SUWEIF',
'DUMYAT': 'DAMIETTA GOVERNORATE',
'AL BAHR AL AHMAR': 'RED SEA',
'AL ISMAILIYAH': 'ISMAILIA GOVERNORATE',
'AL MINYA': 'MINYA',
'SHAMAL SINA': 'NORTH SINAI',
'JANUB SINA': 'SOUTH SINAI',
'BUR SAID': 'PORT SAID',
'SUHAJ': 'SOHAG',
'AS SUWAYS': 'SUEZ'
},
'EN': {
'TARTUMAA': 'TARTU',
'LAANEMAA': 'LAANE',
'SAAREMAA': 'SAARE'
},
'ER': {
'MAAKEL': 'MAEKEL',
'DEBUBAWI KEYIH BAHRI': 'SOUTHERN RED SEA',
'SEMENAWI KEYIH BAHRI': 'NORTHERN RED SEA'
},
'ET': {
'AMARA': 'AMHARA',
'ADIS ABEBA': 'ADDIS ABABA',
'YEDEBUB BIHEROCH BIHERESEBOCH NA HIZBOCH': 'SOUTHERN NATIONS, NATIONALITIES, AND PEOPLES REGION',
'GAMBELA HIZBOCH': 'GAMBELA',
'HARERI HIZB': 'HARARI',
'SUMALE': 'SOMALI'
},
'EZ': {
'JIHOMORAVKY KRAJ': 'SOUTH MORAVIAN',
'ZLINSKY KRAJ': 'ZLIN',
'STREDOCESKY KRAJ': 'CENTRAL BOHEMIA',
'MORAVSKOLEZSKY KRAJ': 'MORAVSKOSLEZSKY'
},
'FI': {
'LAPPI': 'LAPLAND'
},
'FR': {
'CENTRE': 'CENTRE VAL DE LOIRE',
'BRETAGNE': 'BRITTANY',
'CORSE': 'CORSICA',
'LIMOUSIN': 'LIMOSINE'
},
'GA': {
'WESTERN': 'WEST COAST'
},
'GB': {
'NGOUNIE': 'NGOUNI'
},
'GG': {
'TBILISI': 'KALAKI TBILISI',
'MTSKHETIS RAIONI': 'MTSKHETA MTIANETI', # wtf
},
'GM': {
'BAYERN': 'BAVARIA',
'NORDRHEIN WESTFALEN': 'NORTH RHINE WESTPHALIA',
'HESSEN': 'HESSE',
'NIEDERSACHSEN': 'LOWER SAXONY',
'THURINGEN': 'THURINGIA',
'SACHSEN ANHALT': 'SAXONY ANHALT',
'SACHSEN': 'SAXONY',
'BERLIN': 'LAND BERLIN'
},
'GR': {
'ATTIKI': 'ATTICA',
'LARISA': 'THESSALY',
'EVROS': 'EAST MACEDONIA AND THRACE'
},
'GT': {
'SUCHITEPEQUEZ': 'SUCHITEPEQUE'
},
'HA': {
'GRAND ANSE': 'GRANDANS'
},
'HO': {
'ISLAS DE LA BAHIA': 'BAY ISLANDS'
},
'HR': {
'VUKOVARSKO SRIJEMSKA': 'VUKOVAR SIRMIUM',
'SPLITSKO DALMATINSKA': 'SPLIT DALMATIA',
'ISTARSKA': 'ISTRIA',
'BRODSKO POSAVSKA': 'SLAVONSKI BROD POSAVINA',
'MEDIMURSKA': 'MEGIMURSKA',
'ZAGREBACKA': 'ZAGREB COUNTY',
'GRAD ZAGREB': 'ZAGREB'
},
'IC': {
'AUSTURLAND': 'EAST',
'HOFUDBORGARSVAEDI': 'CAPITAL',
'NORDURLAND EYSTRA': 'NORTHEAST',
'NORDURLAND VESTRA': 'NORTHWEST',
'SUDURLAND': 'SOUTH',
'SUDURNES': 'SOUTHERN PENINSULA',
'VESTFIRDIR': 'WESTFJORDS',
'VESTURLAND': 'WEST'
},
'IT': {
'LOMBARDIA': 'LOMBARDY',
'TOSCANA': 'TUSCANY',
'SARDEGNA': 'SARDINIA',
'ABRUZZI': 'ABRUZZO',
'SICILIA': 'SICILY',
'PUGLIA': 'APULIA',
'BASILICATA': 'BASILICATE',
'LAZIO': 'LATIUM',
'MARCHE': 'MARCHES',
'PIEMONTE': 'PIEDMONT',
'VALLE DAOSTA': 'AOSTA VALLEY'
},
'IZ': {
'AL ANBAR': 'ANBAR',
'AL BASRAH': 'BASRA',
'DAHUK': 'DIHOK',
'AT TAMIM': 'KIRKUK',
'NINAWA': 'NINEVEH'
},
'JA': {
'FUKUSHIMA': 'FUKUSHIMA KEN',
'GUMMA': 'GUNMA'
},
'JO': {
'AJLUN': 'AJLOUN',
'AL AQABAH': 'AQABA',
'AL KARAK': 'KARAK',
'AL BALQA': 'BALQA',
'AL MAFRAQ': 'MAFRAQ',
'AT TAFILAH': 'TAFIELAH',
'AZ ZARQA': 'ZARQA',
'JARASH': 'JERASH',
'JORDAN': 'HASHEMITE KINGDOM OF JORDAN',
},
'KG': {
'YSYK KOL': 'ISSYK KUL',
'CHUY': 'CHUYSKAYA',
'BISHKEK': 'GOROD BISHKEK',
'OSH': 'OSH OBLASTY'
},
'LE': {
'LIBAN SUD': 'SOUTH GOVERNORATE'
},
'MC': {
'MACAU': 'MACAO'
},
'MU': {
'AL BURAYMI': 'AL BURAIMI',
'MASQAT': 'MUSCAT',
'ZUFAR': 'DHOFAR'
},
'MV': {
'GNAVIYANI': 'GNYAVIYANI'
},
'MY': {
'PULAU PINANG': 'PENANG'
},
'NL': {
'NOORD BRABANT': 'NORTH BRABANT',
'NOORD HOLLAND': 'NORTH HOLLAND',
'ZUID HOLLAND': 'SOUTH HOLLAND'
},
'NU': {
'ATLANTICO SUR': 'COSTA CARIBE SUR'
},
'PO': {
'LISBOA': 'LISBON'
},
'PS': {
'AIMELIK': 'AIMELIIK'
},
'PU': {
'BOLAMA': 'BOLAMA AND BIJAGOS'
},
'RW': {
'OUEST': 'WESTERN',
'SUD': 'SOUTHERN',
'NORD': 'NORTHERN'
},
'SC': {
'SAINT JOHN CAPISTERRE': 'SAINT JOHN CAPESTERRE',
'SAINT PAUL CAPISTERRE': 'SAINT PAUL CAPESTERRE',
'SAINT THOMAS MIDDLE ISLAND': 'MIDDLE ISLAND'
},
'SE': {
'GRAND ANSE': 'GRAND ANSE PRASLIN'
},
'SL': {
},
'SM': {
'MONTE GIARDINO': 'MONTEGIARDINO',
'SAN MARINO': 'SAN MARINO CITTA'
},
'SP': {
'PAIS VASCO': 'BASQUE COUNTRY',
'NAVARRA': 'NAVARRE',
'ANDALUCIA': 'ANDALUSIA',
'CASTILLA LA MANCHA': 'CASTILLE LA MANCHA',
'CATALUNA': 'CATALONIA',
'CASTILLA Y LEON': 'CASTILLE AND LEON',
'CANARIAS': 'CANARY ISLANDS',
'VALENCIANA': 'VALENCIA',
'ISLAS BALEARES': 'BALEARIC ISLANDS'
},
'SY': {
'HALAB': 'ALEPPO',
'DIMASHQ': 'DAMASCUS',
'HAMAH': 'HAMA',
'AL LADHIQIYAH': 'LATAKIA'
},
'TD': {
'TRINIDAD': 'TRINIDAD AND TOBAGO' # not sure
},
'TP': {
'SAO TOME': 'SAO TOME ISLAND'
},
'TU': {
'DUZCE': 'DUEZCE',
'BARTIN ILI': 'BARTIN',
'ICEL': 'MERSIN',
'GUMUSHANE': 'GUEMUESHANE',
'KARABUK': 'KARABUEK'
},
'TW': {
'KAO HSIUNG': 'KAOHSIUNG',
'TAI PEI': 'TAIPEI CITY'
},
'UZ': {
'SURHKONDARYO': 'SURXONDARYO',
'FARGHONA': 'FERGANA',
'KHORAZM': 'XORAZM',
'QORAQALPOGHISTON': 'KARAKALPAKSTAN',
'NAWOIY': 'NAVOIY'
},
'UV': {
'MOUHOUN': 'BOUCLE DU MOUHOUN'
},
'YM': {
'ADAN': 'ADEN',
'AMRAN': 'OMRAN',
'SANA': 'SANAA'
}
}
LOCATION_TO_PARENT = {
'BY': {
'BUJUMBURA MAIRIE PROVINCE': 'BUJUMBURA',
'BUJUMBURA RURAL PROVINCE': 'BUJUMBURA',
'ISALE': 'BUJUMBURA',
'ROHERO': 'BUJUMBURA',
'RUMONGE': 'BUJUMBURA', # since 2015
},
'CD': {
'AM DJARASS': 'BORKOU ENNEDI TIBESTI',
'AOZOU': 'BORKOU ENNEDI TIBESTI',
'BORKOU REGION': 'BORKOU ENNEDI TIBESTI',
'ENNEDI EST': 'BORKOU ENNEDI TIBESTI',
'ENNEDI OUEST': 'BORKOU ENNEDI TIBESTI',
'FADA': 'BORKOU ENNEDI TIBESTI',
'FAYA LARGEAU': 'BORKOU ENNEDI TIBESTI',
'TIBESTI REGION': 'BORKOU ENNEDI TIBESTI',
'BARH EL GAZEL': 'KANEM', # since 2008
'SALAL': 'KANEM'
},
'CG': {
'AKETI': 'ORIENTALE',
'BAS UELE': 'ORIENTALE',
'BUNIA': 'ORIENTALE',
'HAUT UELE': 'ORIENTALE',
'HAUT LOMANI': 'KATANGA',
'INONGO': 'BANDUNDU',
'ISIRO': 'ORIENTALE',
'ITURI': 'ORIENTALE',
'KASAI': 'KASAI OCCIDENTAL',
'KIKWIT': 'BANDUNDU',
'KOLWEZI': 'KATANGA',
'KONGOLO': 'KATANGA',
'KWILU': 'BANDUNDU',
'LODJA': 'KASAI ORIENTAL',
'LOMAMI': 'KATANGA',
'LUALABA': 'KATANGA',
'LUBUMBASHI': 'KATANGA',