Skip to content

Instantly share code, notes, and snippets.

@EggieCode
Created October 18, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EggieCode/b14cf7e9420cf4301f7a840db51c1c34 to your computer and use it in GitHub Desktop.
Save EggieCode/b14cf7e9420cf4301f7a840db51c1c34 to your computer and use it in GitHub Desktop.
Moment in crime watch script to json file.
#!/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