Last active
January 5, 2024 12:07
-
-
Save jossef/1a6c523f99318286bb1f05efd77fcc9e to your computer and use it in GitHub Desktop.
python script that samples Waze's reported police coordinates and log them with a timestamp
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/env python3 | |
import json | |
import datetime | |
import requests | |
def get_police_coordinates_from_waze(): | |
headers = { | |
"referer": "https://www.waze.com/livemap", | |
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36", | |
} | |
r = requests.get("https://www.waze.com/il-rtserver/web/TGeoRSS", headers=headers) | |
r.raise_for_status() | |
alerts = r.json().get('alerts', []) | |
alerts = filter(lambda x: x['type'] == 'POLICE', alerts) | |
locations = map(lambda x: dict(lat=x['location']['y'], long=x['location']['x']), alerts) | |
locations = list(locations) | |
return locations | |
content = json.dumps(get_police_coordinates_from_waze()) | |
timestamp = int(datetime.datetime.utcnow().timestamp() * 1000) | |
with open("police_coordinates.log", "a") as f: | |
f.write('{}\t{}\n'.format(timestamp, content)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script is used for fun to create a small dataset my personal usage to visualize based on the collected data the police distribution over time.
example output:
This script uses Waze's internal API (scraped from https://www.waze.com/livemap). Judging by the data service uri (
.../il-rtserver/...
) - the results are filtered to Israel. If you wish to find an additional data services, try visiting https://www.waze.com/livemap and use web-dev tools for inspection.