SHARE
TWEET

Untitled

a guest Feb 15th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests, json, datetime
  2.  
  3. PATH = 'https://api.data.gov.sg/v1/transport/taxi-availability?date_time=<date_time>'
  4. query_datetime = datetime.datetime(2019, 10, 30, 0, 0, 0) # 30 oct
  5. oct_31 = datetime.datetime(2019, 10, 31, 0, 0, 0) # 31 oct
  6.  
  7. while query_datetime < oct_31:
  8.     query_datetime_str = query_datetime.strftime('%Y-%m-%d') + 'T' + query_datetime.strftime('%H:%M:%S')
  9.     res = requests.get(PATH.replace('<date_time>', query_datetime_str))
  10.     data = json.loads(res.content)
  11.  
  12.     timestamp = data['features'][0]['properties']['timestamp']
  13.  
  14.     with open(f'data/{timestamp}.json', 'w+') as f:
  15.         f.write(res.content.decode())
  16.  
  17.     query_datetime += datetime.timedelta(seconds=30)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top