bjbus.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ## SPDX-License-Identifier: MIT
  2. import requests
  3. import json
  4. url = 'https://www.bjbus.com/api/api_etaline_list.php?hidden_MapTool=busex2.BusInfo&city=%u5317%u4EAC&pageindex=1&pagesize=30&fromuser=bjbus&datasource=bjbus&clientid=9db0f8fcb62eb46c&webapp=mobilewebapp&what={}'
  5. token = 'eyJhbGciOiJIUzI1NiIsIlR5cGUiOiJKd3QiLCJ0eXAiOiJKV1QifQ.eyJwYXNzd29yZCI6IjY0ODU5MTQzNSIsInVzZXJOYW1lIjoiYmpidXMiLCJleHAiOjE2ODQwNDgxNjZ9.0zgvMMgwk5Gr9XSt3om8hys1ZtYCGe2QB1nPlugbWao'
  6. def search_routes(number):
  7. resp = requests.get(url.format(number))
  8. if resp.status_code != 200:
  9. raise
  10. j = json.loads(resp.content)
  11. result_set = j['response']['resultset']
  12. if len(result_set) > 0:
  13. return result_set['data']['feature']
  14. else:
  15. return []
  16. def search_routes_exact(number):
  17. number_s = str(number)
  18. return list(filter(lambda x: x['lineName'] == number_s, search_routes(number_s)))
  19. def show_line_info(lineId):
  20. url_sel = 'https://www.bjbus.com/api/api_etaline.php?lineId={}&pageNum=1&token=' + token
  21. resp = requests.post(url_sel.format(lineId))
  22. j = json.loads(resp.content)
  23. return j['data']
  24. def show_stops(lineId):
  25. url_eta = 'http://www.bjbus.com/api/api_etastation.php?lineId='+lineId+'&token=' + token
  26. resp = requests.post(url_eta)
  27. j = json.loads(resp.content)
  28. return j['data']
  29. def show_eta(lineId,stopId):
  30. url_eta = 'http://www.bjbus.com/api/api_etartime.php?conditionstr='+lineId+'-'+stopId+'&token=' + token
  31. resp = requests.post(url_eta)
  32. j = json.loads(resp.content)
  33. return j['data']