-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapping.py
65 lines (55 loc) · 1.54 KB
/
mapping.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
57
58
59
60
61
62
63
64
65
import urllib
import sqlite3 as sqlite
import os
def get_map(
latitude,
longitude,
size="512x512",
maptype="terrain",
markercolor="red",
api_file="../google_api.key",
api=None,
zoom=9,
save_file="map.png",
):
# given a latitude and longitude, get a static map from Google
# Maps using their API
if api == None:
if os.path.exists(api_file):
api_read = open(api_file, "r")
api = api_read.readline()
api = api.strip()
else:
print("no api key input and no key file found")
url_call = (
"http://maps.googleapis.com/maps/api/staticmap?"
+ "center="
+ str(latitude)
+ ","
+ str(longitude)
+ "&size="
+ size
+ "&maptype="
+ maptype
+ "&zoom="
+ str(zoom)
+ "&markers=color:"
+ markercolor
+ "%7ClabelG%7C"
+ str(latitude)
+ ","
+ str(longitude)
+ "&key="
+ api
)
urllib.urlretrieve(url_call, save_file)
def get_map_from_db(code, dbfile="/app/data/quakeBotDB.sqlite", **kwargs):
# look in the database for a unique code to get the latitude and
# longitude in order to get a map
connection = sqlite.connect(dbfile)
cur = connection.cursor()
sqlquery = "SELECT latitude,longitude FROM quakes WHERE code = ?"
results = cur.execute(sqlquery, (code,)).fetchall()
if len(results) > 0:
latitude, longitude = results[0]
get_map(latitude, longitude, **kwargs)