-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle.py
46 lines (38 loc) · 1.1 KB
/
google.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
from random import random
from urllib.parse import urlencode
import requests
from config import IMAGE_SIZE
from secrets import GOOGLE_API_KEY
def directions(start, finish):
return requests.get(
'https://maps.googleapis.com/maps/api/directions/json',
params={
'origin': start,
'mode': 'driving',
'avoid': 'highways',
'destination': finish,
'key': GOOGLE_API_KEY,
}
).json()
def streetview_url(*coords):
return (
'https://maps.googleapis.com/maps/api/streetview?{}'.format(
urlencode({
'size': '{}x{}'.format(*IMAGE_SIZE),
'location': '{},{}'.format(*coords),
'fov': 90,
'heading': int(random() * 360),
'pitch': 10,
'key': GOOGLE_API_KEY,
})
)
)
def static_map_url(**params):
return (
'https://maps.googleapis.com/maps/api/staticmap?{}'.format(
urlencode({
**params,
'key': GOOGLE_API_KEY,
}, doseq=True)
)
)