forked from open-data-network/utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocode_domains.py
17 lines (17 loc) · 898 Bytes
/
geocode_domains.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import requests
from sodapy import Socrata
import json
# store api token in creds.txt
with open('creds.json', 'r') as f:
creds = json.loads(f.read())
client = Socrata("odn.data.socrata.com", creds["token"], username=creds['username'], password=creds['password'])
data = requests.get('https://odn.data.socrata.com/resource/jwbj-xtgt.json?$where=region_name%20IS%20NOT%20NULL%20AND%20location%20IS%20NULL').json()
for row in data:
if len(row['region_name'].split(',')) > 2:
location = requests.get('http://nominatim.openstreetmap.org/search/?q=%s&format=json' % (row['region_name'])).json()
else:
location = requests.get('http://nominatim.openstreetmap.org/search/?q=%s,usa&format=json' % (row['region_name'])).json()
if location:
location = location[0]
row['location'] = "(%s, %s)" % (location['lat'], location['lon'])
client.upsert("k53q-ytmx", data)