-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_agencies.py
More file actions
29 lines (19 loc) · 775 Bytes
/
Copy pathget_agencies.py
File metadata and controls
29 lines (19 loc) · 775 Bytes
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
import urllib2, json, time
def get_agencies():
#Base URL, json comes back by default
base = 'http://www.gtfs-data-exchange.com/api/agencies'
# No queries here
query=''
# Formulate URL request and format response as json object
response = urllib2.urlopen(base + query, timeout=30)
str_response = response.read().decode('utf-8')
agencies = json.loads(str_response)['data']
# Prints entirety of json response
#print(buses)
output = ''
# For each agency in response, print a few pieces of data.
for agency in agencies:
output = agency['name'] + ' in ' + agency['state'] + ', ' + agency['country'] + ' was last updated on ' + time.strftime('%b %d, %Y', time.localtime(agency['date_last_updated']))
print output
if __name__ == '__main__':
get_agencies()