Skip to content

Commit

Permalink
add adaption of continents script from @zelima
Browse files Browse the repository at this point in the history
also grab a few other codes from geonames
  • Loading branch information
ewheeler committed Jun 9, 2016
1 parent 31e46b8 commit 2ab638a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/geoname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python
# -*- coding: utf-8 -*

import urllib
import csv

url = 'http://download.geonames.org/export/dump/countryInfo.txt'
dest = urllib.urlopen(url)


def get_data():
'''gets data necessary from retrievd file
'''
for line in dest.readlines():
if line[0] != '#' and line[0] != '\n':
splited = line.split('\t')
print splited
# iso3166-alpha3, capital, continent code, tld, languages, geoname id
yield splited[1], splited[5], splited[8], splited[9], splited[15], splited[16]

header = ['ISO3166-1-Alpha-3', 'Capital', 'Continent', 'TLD', 'Languages', 'geonameid']
with open('data/geoname.csv', 'wb') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(header)
for row in get_data():
csv_writer.writerow(row)

0 comments on commit 2ab638a

Please sign in to comment.