#!/usr/bin/python # # Batchtraveller # # Finds out travel times and distances for pairs of start and end locations # using the google.directions package for Python to access google maps. # # Copyright (c) 2011 Gerrit Hirschfeld # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import csv, Tkinter, tkFileDialog from google.directions import GoogleDirections gd = GoogleDirections("your-google-directions-key") #Daten einlesen root = Tkinter.Tk() filename = tkFileDialog.askopenfile(parent=root,mode='rb',title='Choose a file') reader = csv.reader(filename, delimiter=';') zips=[] for row in reader: zips.append(row) headers=[] headers.append(zips[0]) #Der Loop start=[] end=[] times=[] miles=[] for i in range(len(zips)): res = gd.query(zips[i][0], zips[i][1]) temp=res.result["Directions"]["Duration"]["seconds"] start.append(zips[i][0]) end.append(zips[i][1]) miles.append(res.distance) times.append(temp) print i outfilename = tkFileDialog.asksaveasfilename(parent=root,title='Save results as') fout=open(outfilename, 'wb') out = csv.writer(fout, csv.excel, delimiter=';') for i in range(len(times)): data=start[i], end[i], times[i], miles[i] out.writerow(data)