-
Notifications
You must be signed in to change notification settings - Fork 23
/
lat_long_expansion.py
31 lines (24 loc) · 968 Bytes
/
lat_long_expansion.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
import json
import reverse_geocoder as rg
lat_longs = {}
with open("dataset/business.json") as business_json:
for line in business_json.readlines():
item = json.loads(line)
if item["latitude"] and item["longitude"]:
lat_longs[item["business_id"]] = {
"lat_long": (item["latitude"], item["longitude"]),
"city": item["city"]
}
result = {}
business_ids = list(lat_longs.keys())
locations = rg.search([value["lat_long"] for value in lat_longs.values()])
for business_id, location in zip(business_ids, locations):
result[business_id] = {
"country": location["cc"],
"name": location["name"],
"admin1": location["admin1"],
"admin2": location["admin2"],
"city": lat_longs[business_id]["city"]
}
with open("dataset/businessLocations.json", "w") as business_locations_json:
json.dump(result, business_locations_json, indent=4, sort_keys=True)