public
Last active

Search where people are moving in Germany

  • Download Gist
citysearch.py
Python
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
# coding: utf-8
 
# requires: pattern http://www.clips.ua.ac.be/pages/pattern
from pattern.web import *
import csv
import sys
 
# yeah I know
reload(sys)
sys.setdefaultencoding("utf-8")
 
# engine = Google(license='XXX', throttle=2.0)
#engine = Twitter(license=None)
engine = Bing()
 
 
phrase = '"von %s nach %s gezogen"'
cities = ["Berlin", "Hamburg", "München", "Köln", "Frankfurt am Main", "Stuttgart", "Düsseldorf", "Dortmund", "Essen", "Bremen", "Leipzig", "Dresden", "Hannover", "Nürnberg", "Duisburg", "Bochum", "Wuppertal", "Bonn", "Bielefeld", "Mannheim", "Karlsruhe", "Münster", "Wiesbaden", "Augsburg", "Aachen", "Mönchengladbach", "Gelsenkirchen", "Braunschweig", "Chemnitz", "Kiel"]
 
csv_writer = csv.writer(open("cities.csv", 'wb'), delimiter="\t", quoting=csv.QUOTE_NONNUMERIC)
 
csv_writer.writerow(["Source", "Target", "Weight"])
 
for i in cities:
for j in cities:
results = engine.search(phrase % (i,j), type=SEARCH)
csv_writer.writerow([i, j, results.total])

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.