Skip to content

Instantly share code, notes, and snippets.

@pierky
Created April 8, 2015 14:35
Show Gist options
  • Save pierky/00f7fcdbd490f7e393f7 to your computer and use it in GitHub Desktop.
Save pierky/00f7fcdbd490f7e393f7 to your computer and use it in GitHub Desktop.
Python script to build a country code / capital city lat-lon mapping table
# Processing of http://opengeocode.org/cude/download.php?file=/home/fashions/public_html/opengeocode.org/download/cow.txt
#
# Used on my blog post http://blog.pierky.com/displaying-pmacct-country-code-on-a-kibana-4-map
#
# Output:
#
# {
# "CC": "lat,lon",
# ...
# }
import csv
import json
Data = {}
with open('cow.txt', 'rb') as CSV:
reader = csv.reader( CSV, delimiter=';' )
for row in reader:
try:
cc=row[0]
lat=row[45].strip()
lon=row[46].strip()
if len(cc) == 2 and lat and lon:
Data[ cc ] = "{lat},{lon}".format( lat=lat, lon=lon )
except:
pass
print( json.dumps( Data ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment