|
|
|
@ -1,5 +1,6 @@ |
|
|
|
from urllib.parse import urlencode |
|
|
|
from urllib.request import urlopen |
|
|
|
from disk_cache import disk_cache |
|
|
|
import json |
|
|
|
from sensitive import api |
|
|
|
|
|
|
|
@ -10,7 +11,7 @@ def get_data(type, api_key=api, timeout=None, **args): |
|
|
|
args['format'] = 'json' |
|
|
|
url = base_url.format(type=type, query=urlencode(args)) |
|
|
|
if timeout is not None: |
|
|
|
response = urlopen(url,timeout = timeout) |
|
|
|
response = urlopen(url, timeout=timeout) |
|
|
|
else: |
|
|
|
response = urlopen(url) |
|
|
|
data = json.load(response)['bustime-response'] |
|
|
|
@ -25,13 +26,16 @@ def get_times(stop_id, api_key=api, timeout=None): |
|
|
|
return get_data('getpredictions', api_key, stpid=stop_id, timeout=timeout) |
|
|
|
|
|
|
|
|
|
|
|
@disk_cache |
|
|
|
def get_routes(api_key=api, timeout=None): |
|
|
|
return get_data('getroutes', api_key, timeout=timeout) |
|
|
|
|
|
|
|
|
|
|
|
@disk_cache |
|
|
|
def get_directions(route, api_key=api, timeout=None): |
|
|
|
return get_data('getdirections', api_key, rt=route, timeout=timeout) |
|
|
|
|
|
|
|
|
|
|
|
@disk_cache |
|
|
|
def get_stops(route, direction, api_key=api, timeout=None): |
|
|
|
return get_data('getstops', api_key, rt=route, dir=direction, timeout=timeout) |