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.

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