You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

7 years ago
7 years ago
  1. from urllib.parse import urlencode
  2. from requests import get
  3. import json
  4. import datetime
  5. import argparse
  6. test = False
  7. test = True
  8. api = "***REMOVED***"
  9. def get_data(type,api_key = api,**args):
  10. base_url = "http://www.ctabustracker.com/bustime/api/v2/{type}?{query}"
  11. args['key'] = api_key
  12. args['format'] = 'json'
  13. url = base_url.format(type = type,query = urlencode(args))
  14. print(url)
  15. input()
  16. response = get(url)
  17. data = json.loads(response.text)
  18. return data['bustime-response']
  19. # print(url)
  20. def print2d(values):
  21. pass
  22. def get_times(stop_id,api_key = api):
  23. return get_data('getpredictions',api_key,stpid=stop_id)
  24. def get_routes(api_key = api):
  25. return get_data('getroutes',api_key)
  26. def get_directions(route,api_key = api):
  27. return get_data('getdirections',api_key,rt=route)
  28. def get_stops(route,direction,api_key = api):
  29. return get_data('getstops',api_key,rt = route,dir=direction)
  30. if __name__ == "__main__":
  31. if test:
  32. data = get_times('4752')
  33. else:
  34. parser = argparse.ArgumentParser(prog = 'ctabus')
  35. parser.add_argument('arg',metavar = 'stop-id | cross streets')
  36. parser.add_argument('-r','--route')
  37. parser.add_argument('-d','--direction')