Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.