Update cities data and add script

This commit is contained in:
Gabriel Augendre 2019-07-11 00:00:32 +02:00
parent 510bec8964
commit a24585c837
2 changed files with 36773 additions and 35337 deletions

72081
cities.py

File diff suppressed because it is too large Load diff

29
convert_cities.py Normal file
View file

@ -0,0 +1,29 @@
# This expects a file named "correspondance-code-insee-code-postal.json"
# You can find one here : https://public.opendatasoft.com/explore/dataset/correspondance-code-insee-code-postal/export/
import json
with open("correspondance-code-insee-code-postal.json", "r") as f:
data = json.load(f)
mapping = dict()
failed = []
duplicates = []
for base_item in data:
item = base_item.get("fields")
if not item:
failed.append(base_item)
insee_com = item.get("insee_com")
if insee_com:
if insee_com in mapping:
duplicates.append(base_item)
mapping[insee_com] = {
"name": item.get("nom_comm"),
"zip_code": item.get("postal_code"),
}
else:
failed.append(base_item)
import pprint
with open("cities.py", "w") as writef:
writef.write(pprint.pformat(mapping, indent=4, compact=True))
writef.flush()