Skip to content

Instantly share code, notes, and snippets.

@drsm79
Created September 17, 2011 08:07
Show Gist options
  • Save drsm79/1223747 to your computer and use it in GitHub Desktop.
Save drsm79/1223747 to your computer and use it in GitHub Desktop.
Cities parsing script
# encoding: utf-8
"""
Quick script to dump out the long/lat of most of the capital cities in the world (I removed ones with unicode characters).
"""
import csv
import json
cities = u"""Bulgaria,Sofia,42.40N 023.18E
Czech Republic,Prague,50.06N 014.26E
Eritrea,Asmera,15.20N 038.58E
Estonia,Tallinn,59.22N 024.48E
Fiji,Suva,18.08S 178.25E
Finland,Helsinki,60.08N 025.00E
Iceland,Reykjavik,06.09N 021.51W
India,New Delhi,28.37N 077.13E
Ireland,Dublin,53.20N 006.15W
Italy,Rome,41.48N 012.36E
Japan,Tokyo,35.40N 139.45E
Netherlands,Amsterdam,52.21N 004.54E
New Zealand,Wellington,41.17S 174.47E
Swaziland,Mbabane,26.20S 031.08E
Sweden,Stockholm,59.20N 001.03E
Switzerland,Bern,46.57N 007.26E
Tunisia,Tunis,36.48N 010.11E
United Kingdom,London,51.30N 000.10W
United States of America,Washington,38.55N 077.00W
Zaire,Kinshasa,04.18S 015.18E
Zambia,Lusaka,15.26S 028.20E
Zimbabwe,Harare,17.50S 031.03E"""
cities = csv.reader(cities.split('\n'), delimiter=',', quotechar='|')
for row in cities:
to_json = {}
to_json['country'] = row[0]
to_json['city'] = row[1]
lat, longi = row[2].split()
to_json['latitude'] = lat
to_json['longitude'] = longi
print json.dumps(to_json)
@drsm79
Copy link
Author

drsm79 commented Sep 17, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment