-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (44 loc) · 1.82 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime
from typing import collection
from mitmproxy.http import HTTPFlow
import requests
from constants import API_PARAMS
endpoint = 'https://api.tomtom.com/search/2/geocode/{}.json'
def _add_stop(flow: HTTPFlow, latitude: float, longitude: float) -> HTTPFlow:
"""Add a stop to the given Google Maps request."""
url = flow.request.url
if not url.startswith('https://www.google.com/maps/dir'):
return
print(f'[?] Request intercepted: {url}')
url = url.split('/')
for i, section in enumerate(url):
if section.startswith('@'):
break
url.insert(i, f"'{latitude},{longitude}'")
print(
f'[+] Injected detour with latitude {latitude}, '
f'longitude {longitude}'
)
flow.request.url = '/'.join(url)
print(f'[?] New request string: {flow.request.url}')
def _geocode_address(address: str) -> Collection[float]:
"""Given an address, return the latitude and longitude values."""
print(f'[?] Querying address: {endpoint.format(address)}')
result = requests.get(
endpoint.format(address), params=API_PARAMS
).json()['results'][0]['position']
print(f'[!] Found location: {result}')
return result['lat'], result['lon']
def _nearest_crime(longitude: float, latitude: float) -> str:
"""Find the nearest crime to a given latitude/longitude point."""
print(f'[?] Querying crimes: {longitude, latitude}')
current_date = datetime.now().strftime('%Y-%m')
print(current_date)
results = requests.get(
'https://data.police.uk/api/crimes-at-location',
params={'lat': latitude, 'lng': longitude, 'date': current_date}
)
return results.text
def _crime_from_address(address: str) -> str:
"""Find the nearest crime to a given address."""
return _nearest_crime(*_geocode_address(address))