-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmap-printout.py
34 lines (31 loc) · 975 Bytes
/
gmap-printout.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
import json, urllib, re
from urllib import urlencode
import googlemaps
import tempfile
import win32api
import win32print
start = raw_input("Start Address: ")
finish = raw_input("finish address: ")
url = 'http://maps.googleapis.com/maps/api/directions/json?%s' % urlencode((
('origin', start),
('destination', finish)
))
ur = urllib.urlopen(url)
result = json.load(ur)
filename = "output.txt"
with open(filename, "w") as output:
for i in range (0, len (result['routes'][0]['legs'][0]['steps'])):
s = (result['routes'][0]['legs'][0]['steps'][i]['html_instructions'])
d = (result['routes'][0]['legs'][0]['steps'][i]['distance']['text'])
l = (result['routes'][0]['legs'][0]['steps'][i]['duration']['text'])
s = re.sub('<[A-Za-z\/][^>]*>', '', s)
print s + d + l
output.writelines(s + " " + d + " " + l + '\n')
win32api.ShellExecute (
0,
"print",
filename,
'/d:"%s"' % win32print.GetDefaultPrinter (),
'.',
0
)