Created
January 2, 2019 13:47
-
-
Save Proteusiq/c82cb5d7a634fd8ecb4b61c5d5f12854 to your computer and use it in GitHub Desktop.
speedcontrol.py
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
from datetime import datetime | |
import requests | |
url = 'https://www.fartkontrol.nu/ajax.php' | |
dawa_url = 'https://dawa.aws.dk/postnumre/reverse' | |
data = {'json':'''{"action":"controls_fetch","uid":null,"app":0,"my_coords":{"Ya":0,"Za":0,"a c":0},"types":["1","-1","-1",null,"1"]}'''} | |
r = requests.get(url,params=data) | |
if r.ok: | |
d = r.json() | |
else: | |
raise ConnectionError('Failed Connection') | |
control = d['controls']['coordinates'] | |
time = d['controls']['time'] | |
count = len(control) | |
read_time = datetime.fromtimestamp(time)#.strftime('%Y-%m-%d %H:%M:%S') | |
print(f'{count} Speed Control Report: {read_time}\n') | |
for c in control.values(): | |
moment = datetime.fromtimestamp(int(c['time'])) | |
#Lat = Y Long = X | |
latitude = float(c['y'])/1e7 | |
longitude = float(c['x'])/1e7 | |
near = c['near'] | |
thanks = c['count_thanks'] | |
print(f'{count}. {moment}\nPolice speed control located at\n\t{near}\n\tLatitude: {latitude}\n\tLongitude: {longitude}\n {thanks} confirmations') | |
# dawa y = longitude & x = latitude??? | |
l = requests.get(dawa_url,params={'y':longitude,'x':latitude}).json() | |
if 'navn' in l.keys(): | |
print(f'Kommune: {l["navn"]}') | |
print('\n'*5) | |
count-=1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment