-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_addresses.py
53 lines (40 loc) · 1.34 KB
/
update_addresses.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
import io
import json
import os
from pprint import pprint
from googlemaps_geocoding import get_geodata
from tqdm import tqdm
# Confidential info filepath
saved_responses_path = "data_store/form_responses.json"
# Will store the data
tigres = {}
# Populate dict from latest saved version
if os.path.isfile(saved_responses_path):
with io.open(saved_responses_path) as json_file:
tigres = json.load(json_file)
else:
print("""*********************************************
************ File not found *************
*********************************************""")
quit()
# Loop for every member
for tigre, data in tqdm(tigres.items(),"Updating..."):
# Check update condition
if not data.get('Updated GPS',False):
# Get response address
cp = data.get('Código Postal','')
# Call geocoding API
update = get_geodata(address=cp + ", México")
# Update or write data from API response
if 'GPS' in data:
data['GPS'].update(update)
else:
data['GPS'] = update
# Unmark tag
data['Updated GPS'] = True
# pprint({cp:update})
# Overwrite data
tigres[tigre] = data
# Save to a file
with io.open(saved_responses_path,'w') as json_output:
json.dump(tigres,json_output,ensure_ascii=False,indent=4,sort_keys=True)