1
0
Fork 0
forked from 0x2620/oxjs

update geo tools

This commit is contained in:
rolux 2011-11-30 15:28:01 +01:00
commit 1b2a7a0eed
3 changed files with 265 additions and 91 deletions

View file

@ -8,7 +8,11 @@ import sys
import urllib
CACHE = sys.argv[-1] == '-cache'
DATA = ox.jsonc.loads(ox.file.read_file('../jsonc/countries.jsonc'))
try:
DATA = ox.jsonc.loads(ox.file.read_file('../jsonc/countries.jsonc'))
except:
ox.file.write_file('../jsonc/debug.json', ox.js.minify(ox.file.read_file('../jsonc/countries.jsonc')))
sys.exit()
LOGS = {}
def decode_wikipedia_id(id):
@ -50,7 +54,7 @@ def get_countries():
return country['code'] if 'code' in country else u'ZZ ' + country['name']
countries = map(lambda x: parse(x), DATA['wikipedia'])
# ISO 3166-3
html = read_wikipedia_url('ISO 3166-3')
html = read_wikipedia_url('ISO 3166-3').replace('Rhodesia', 'Southern Rhodesia') # FIXME: can this be avoided?
matches = re.compile('<td id="([A-Z]{4})">.*?<a href="/wiki/(.*?)".*?>', re.DOTALL).findall(html)
countries += map(lambda x: parse(x), matches)
# ISO 3166-1 alpha-2
@ -68,6 +72,7 @@ def get_countries():
print year, '-' * 64
for x in map(lambda x: x['name'], filter(lambda x: not exists(x), map(lambda x: parse(x), matches))):
print x
sys.exit()
'''
# Country data
countries = sorted(countries, key=sort)
@ -92,6 +97,9 @@ def get_country_data(country):
match = re.search('"/wiki/\.(\w{2})"', html)
if match:
country['code'] = match.group(1).upper()
# alias
if country['code'] in DATA['alias']:
country['alias'] = True
# continents and regions
for continent, regions in DATA['continents'].iteritems():
for region, countries in regions.iteritems():
@ -255,8 +263,9 @@ if __name__ == '__main__':
LOGS['dissolved independent'] = 0
LOGS['dissolved dependent'] = 0
LOGS['dissolved disputed'] = 0
LOGS['alias'] = 0
for country in countries:
key = ' '.join([
key = 'alias' if 'alias' in country else ' '.join([
'dissolved' if 'dissolved' in country else 'current',
'disputed' if 'disputed' in country else ('dependent' if 'dependency' in country else 'independent')
])