-
Notifications
You must be signed in to change notification settings - Fork 0
/
regioncodes.void
32 lines (25 loc) · 1.01 KB
/
regioncodes.void
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
"""
# provide latitude & longitude, return eBird "regionCode"
Written by Jess Sullivan
@ https://transscendsurvival.org/
"""
import requests
import json
def get_regioncode(lat, lon):
# this municipal api is a publicly available, no keys needed afaict
census_url = str('https://geo.fcc.gov/api/census/area?lat=' +
str(lat) +
'&lon=' +
str(lon) +
'&format=json')
# send out a GET request:
payload = {}
get = requests.request("GET", census_url, data=payload)
# parse the response, all api values are contained in list 'results':
response = json.loads(get.content)['results'][0]
# use the last three digits from the in-state fips code as the "subnational 2" identifier:
fips = response['county_fips']
# assemble and return the "subnational type 2" code:
regioncode = 'US-' + response['state_code'] + '-' + fips[2] + fips[3] + fips[4]
print('formed region code: ' + regioncode)
return regioncode