Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/python2
  2. #-*- coding: utf-8 -*-
  3.  
  4. import requests
  5. import json
  6.  
  7. ROUTES_URL = 'http://car.hccepb.gov.tw/TMap/MapGISData.asmx/Get_DDLRouteList'
  8. STOP_INFO_URL = 'http://car.hccepb.gov.tw/TMap/MapGISData.asmx/GetStopInfo'
  9. HEADERS = {
  10.     'Content-Type': 'application/json'
  11. }
  12.  
  13. def get_routes():
  14.     return json.loads(
  15.         json.loads(
  16.             requests.post(
  17.                 ROUTES_URL,
  18.                 headers=HEADERS
  19.             ).text
  20.         )['d']
  21.     )  
  22.  
  23. def get_stop_info(route_id=1):
  24.     return json.loads(
  25.                 json.loads(
  26.                     requests.post(
  27.                         STOP_INFO_URL,
  28.                         headers=HEADERS,
  29.                         data=json.dumps({'run_id': route_id}),
  30.                     ).text
  31.                 )['d']
  32.     )  
  33.  
  34.  
  35. a = get_routes()
  36.  
  37. for x in a:
  38.     print x['run_id'], x['name'].encode('utf-8')
  39.  
  40. for x in a:
  41.     print json.dumps(get_stop_info(x['run_id']), ensure_ascii=False, indent=2).encode('utf-8')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement