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')
])

View file

@ -22,7 +22,7 @@ for file in os.listdir(svg_path):
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
if sys.argv[-1] == '-png':
if sys.argv[-1] != '-nopng':
for file in os.listdir('../png/flags/'):
if file[-4:] == '.png':
country = file[:-4]
@ -31,15 +31,16 @@ if sys.argv[-1] == '-png':
image = Image.open(png_file)
# include 4096 to overwrite manually generated image
for size in [4096, 1024, 256, 64, 16]:
image = image.resize((size, size), Image.ANTIALIAS)
if size < 4096:
image = image.resize((size, size), Image.ANTIALIAS)
image.save(png_file.replace('/4096/', '/%d/' % size))
image = Image.new('RGB', (1152,1152))
image = Image.new('RGB', (1216, 1216))
f = open('../json/countries.json')
countries = json.loads(f.read())
f.close()
for i, country in enumerate(countries):
file = png_path.replace('/4096/', '/64/') + country['code'] + '.png'
if os.path.exists(file):
image.paste(Image.open(file), (i % 18 * 64, int(i / 18) * 64))
image.paste(Image.open(file), (i % 19 * 64, int(i / 19) * 64))
image.save('../png/icons.png')