Created
October 18, 2016 18:19
-
-
Save EggieCode/b14cf7e9420cf4301f7a840db51c1c34 to your computer and use it in GitHub Desktop.
Moment in crime watch script to json file.
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
#!/usr/bin/python | |
import requests | |
import json | |
import re | |
import datetime | |
from html.parser import HTMLParser | |
DATA = {} | |
try: | |
with open("data.json") as f: | |
DATA = json.loads(f.read()) | |
except: | |
pass | |
URL = 'http://amomentincrime.s3.amazonaws.com/index.html' | |
body = requests.get(URL).text | |
res = re.findall("([0-9]{2,3}\.[0-9]{0,5})%", body, flags=re.IGNORECASE| re.MULTILINE) | |
now = datetime.datetime.utcnow() | |
DATA[res[0]] = now.isoformat() | |
with open("data.json", "w") as f: | |
f.write(json.dumps(DATA)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment