several minor geolocation bugs fixed (fixes #63, #135, #162, #209)

pull/228/head
Igor Chubin 6 years ago
parent 4dfa7f5ecc
commit 2844a94c88

@ -105,7 +105,9 @@ def ip2location(ip_addr):
pass
if ';' in location:
location = "%s,%s" % (location.split(';')[3], location.split(';')[1])
location = location.split(';')[3], location.split(';')[1]
else:
location = location, None
return location
@ -129,8 +131,12 @@ def get_location(ip_addr):
# except:
# pass
if city is None:
city = ip2location(ip_addr)
return (city or NOT_FOUND_LOCATION), country
city, country = ip2location(ip_addr)
if city:
return city, country
else:
return NOT_FOUND_LOCATION, None
def location_canonical_name(location):
@ -198,17 +204,17 @@ def location_processing(location, ip_addr):
full_address = geolocation['address']
else:
location = NOT_FOUND_LOCATION #location[1:]
try:
query_source_location = get_location(ip_addr)
except:
query_source_location = NOT_FOUND_LOCATION, None
query_source_location = None, None
country = None
if location is None or location == 'MyLocation':
query_source_location = get_location(ip_addr)
location, country = query_source_location
if is_ip(location):
location, country = get_location(location)
if location.startswith('@'):
try:
location, country = get_location(socket.gethostbyname(location[1:]))

@ -178,14 +178,14 @@ def wttr(location, request):
[ip_addr, user_agent, orig_location_utf8, location_utf8, use_imperial, lang])))
if country and location != NOT_FOUND_LOCATION:
location = "%s, %s" % (location, country)
location = "%s,%s" % (location, country)
# We are ready to return the answer
try:
if png_filename:
options = {
'lang': None,
'location': "%s,%s" % (location, country)}
'location': location}
options.update(query)
cached_png_file = wttrin_png.make_wttr_in_png(png_filename, options=options)

Loading…
Cancel
Save