Skip to content

Instantly share code, notes, and snippets.

@Gijs-Koot
Created March 25, 2018 11:37
Show Gist options
  • Save Gijs-Koot/fb0d402f49b656154533358b8ca0f666 to your computer and use it in GitHub Desktop.
Save Gijs-Koot/fb0d402f49b656154533358b8ca0f666 to your computer and use it in GitHub Desktop.
scrape ov fiets data
import requests
import time
import datetime
import json
from hashlib import md5
fn = "./ovfietsdata.json.lines"
while True:
now = datetime.datetime.now().isoformat()
try:
data = requests.get("http://fiets.openov.nl/locaties.json").json()
txt = json.dumps(data)
h = md5(txt.encode('utf-8')).hexdigest()
data["received"] = now
print("{now} Received data hash {h}".format(now = now, h = h))
with open(fn, 'a') as f:
f.write(txt + "\n")
except Exception as e:
print(now, e)
with open(fn, 'a') as f:
f.write("{now} {e}\n".format(now = now, e = e))
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment