-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgmap-stats.py
33 lines (26 loc) · 899 Bytes
/
gmap-stats.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
import polyline
import requests
import pickle
import shutil
import csv
import math
import maputils
csvfile = open('stats.tsv', 'rb')
stats = csv.reader(csvfile, delimiter='\t')
routes = [ list(eval(row[1])) for row in stats ]
for i in xrange(len(routes)):
# for i in xrange(len(routes)-1,len(routes)):
filename = 'pics/' + '{:03}'.format(i) + '.png'
# route = routes[i]
route = routes[i]
poly = maputils.getPoly(route, 0.15)
url = maputils.mapUrl(poly)
r = requests.get(url, stream=True)
if r.status_code == 200:
with open(filename, 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
print len(url), len(url) - len(poly), len(poly), len(poly)/float(len(polyline.decode(poly))), filename #, routes[i]
else:
print len(url), len(url) - len(poly), len(poly), len(poly)/float(len(polyline.decode(poly))), r.status_code, 'ERROR'
break