-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add adaption of continents script from @zelima
also grab a few other codes from geonames
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |