Created
March 25, 2018 11:37
-
-
Save Gijs-Koot/fb0d402f49b656154533358b8ca0f666 to your computer and use it in GitHub Desktop.
scrape ov fiets data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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