update geo and geo tools (fix for palestine, remove image urls)
This commit is contained in:
parent
3fa654a815
commit
8e490eca2e
5 changed files with 6944 additions and 7547 deletions
|
|
@ -9,7 +9,7 @@ import ox
|
|||
import re
|
||||
|
||||
"""
|
||||
run this, then html/geo.html, then fix JSON
|
||||
run this, then html/geo.html, then py/fix_json.py
|
||||
|
||||
311 countries
|
||||
-- sovereign, dependent and disputed countries according to
|
||||
|
|
@ -245,6 +245,7 @@ geo = {
|
|||
'Kosovo': 'Kosova (Kosovo)',
|
||||
'Macedonia': 'Former Yugoslav Republic of Macedonia',
|
||||
'Myanmar': 'Burma',
|
||||
'Palestine': 'Palestinian Territories',
|
||||
'Republic of the Congo': 'Congo',
|
||||
'Sahrawi': 'Western Sahara',
|
||||
'United Kingdom': 'UK',
|
||||
|
|
@ -283,7 +284,7 @@ geo = {
|
|||
'North Vietnam': ['Ha Giang, Vietnam', 'Lai Chau, Vietnam', 'Thua Thien-Hue, Vietnam'],
|
||||
'Northern Cyprus': ['Karpass, Cyprus', 'Kokkina, Cyprus', 'Lympia, Cyprus'],
|
||||
'Pacific Islands': ['Marshall Islands', 'Micronesia', 'Northern Mariana Islands', 'Palau'],
|
||||
'Palestine': ['71, Israel', 'El-arish Rafah, Egypt'],
|
||||
# 'Palestine': ['71, Israel', 'El-arish Rafah, Egypt'],
|
||||
'Panama Canal Zone': ['Amador, Panama', 'Fort Sherman, Panama'],
|
||||
'Sahrawi': ['Western Sahara'],
|
||||
'Saint Helena': ['Ascension Island', 'Longwood, Saint Helena', 'Tristan da Cunha'], # in case results are us-biased
|
||||
|
|
@ -1071,6 +1072,8 @@ def get_countries():
|
|||
# google name
|
||||
if country['name'] in geo['google_name']:
|
||||
country['googleName'] = geo['google_name'][country['name']]
|
||||
else:
|
||||
country['googleName'] = country['name']
|
||||
# other
|
||||
country['other'] = country['name'] in geo['other']
|
||||
# imdb
|
||||
|
|
@ -1097,23 +1100,28 @@ def get_country_flag(code, url):
|
|||
# max width on wikipedia
|
||||
width = 2048
|
||||
img = read_url(url)
|
||||
file = '../png/flags/' + str(width) + '/' + code + '.png'
|
||||
png_file = '../png/flags/' + str(width) + '/' + code + '.png'
|
||||
if url[-4:] == '.svg':
|
||||
write_file('../svg/flags/' + code + '.svg', img)
|
||||
# fixme: remove conditional later
|
||||
# (wikipedia tended to time out)
|
||||
if not os.path.exists(file):
|
||||
svg_file = '../svg/flags/' + code + '.svg'
|
||||
update_image = not os.path.exists(svg_file) or read_file(svg_file) != img
|
||||
if update_image:
|
||||
write_file('../svg/flags/' + code + '.svg', img)
|
||||
if not os.path.exists(png_file) or update_image:
|
||||
png = read_url(url.replace('/commons/', '/commons/thumb/') + '/' + str(width) + 'px-.png')
|
||||
write_file(file, png)
|
||||
png = Image.open(file)
|
||||
write_file(png_file, png)
|
||||
png = Image.open(png_file)
|
||||
else:
|
||||
write_file(file, img)
|
||||
png = Image.open(file)
|
||||
png = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
|
||||
write_image(file, png)
|
||||
update_image = not os.path.exists(png_file) or read_file(png_file) != img
|
||||
if update_image:
|
||||
write_file(png_file, img)
|
||||
png = Image.open(png_file)
|
||||
png = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
|
||||
write_image(png_file, png)
|
||||
else:
|
||||
png = Image.open(png_file)
|
||||
for width in [256, 32]:
|
||||
file = '../png/flags/' + str(width) + '/' + code + '.png'
|
||||
if not os.path.exists(file) or True:
|
||||
if not os.path.exists(file) or update_image:
|
||||
png_ = png.resize((width, int(round(width / png.size[0] * png.size[1]))), Image.ANTIALIAS)
|
||||
write_image(file, png_)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue