Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active January 5, 2024 12:07
Show Gist options
  • Save jossef/1a6c523f99318286bb1f05efd77fcc9e to your computer and use it in GitHub Desktop.
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
#!/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))
@jossef
Copy link
Author

jossef commented Oct 12, 2019

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:

1570872093865	[{"lat": 30.799728, "long": 35.244229}, {"lat": 30.800868, "long": 35.245391}, {"lat": 29.988384, "long": 35.075879}, {"lat": 30.594309, "long": 34.887764}, {"lat": 29.987128, "long": 35.074517}, {"lat": 31.301152, "long": 34.819982}, {"lat": 31.376166, "long": 34.617951}, {"lat": 31.36918, "long": 34.794769}, {"lat": 31.601478, "long": 34.780206}, {"lat": 31.190627, "long": 34.93618}, {"lat": 31.302046, "long": 34.817619}, {"lat": 31.207646, "long": 34.897435}, {"lat": 32.047237, "long": 34.765833}, {"lat": 32.162638, "long": 34.832857}, {"lat": 32.159925, "long": 34.815545}, {"lat": 32.107968, "long": 34.807092}, {"lat": 32.024141, "long": 34.963877}, {"lat": 32.057942, "long": 34.765716}]
1570872103029	[{"lat": 30.799728, "long": 35.244229}, {"lat": 30.800868, "long": 35.245391}, {"lat": 29.988384, "long": 35.075879}, {"lat": 30.594309, "long": 34.887764}, {"lat": 29.987128, "long": 35.074517}, {"lat": 31.301152, "long": 34.819982}, {"lat": 31.376166, "long": 34.617951}, {"lat": 31.36918, "long": 34.794769}, {"lat": 31.601478, "long": 34.780206}, {"lat": 31.190627, "long": 34.93618}, {"lat": 31.302046, "long": 34.817619}, {"lat": 31.207646, "long": 34.897435}, {"lat": 32.047237, "long": 34.765833}, {"lat": 32.162638, "long": 34.832857}, {"lat": 32.159925, "long": 34.815545}, {"lat": 32.107968, "long": 34.807092}, {"lat": 32.024141, "long": 34.963877}, {"lat": 32.057942, "long": 34.765716}]


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment