parent
4dfa7f5ecc
commit
2844a94c88
2 changed files with 15 additions and 9 deletions
|
|
@ -105,7 +105,9 @@ def ip2location(ip_addr):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if ';' in location:
|
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
|
return location
|
||||||
|
|
||||||
|
|
@ -129,8 +131,12 @@ def get_location(ip_addr):
|
||||||
# except:
|
# except:
|
||||||
# pass
|
# pass
|
||||||
if city is None:
|
if city is None:
|
||||||
city = ip2location(ip_addr)
|
city, country = ip2location(ip_addr)
|
||||||
return (city or NOT_FOUND_LOCATION), country
|
|
||||||
|
if city:
|
||||||
|
return city, country
|
||||||
|
else:
|
||||||
|
return NOT_FOUND_LOCATION, None
|
||||||
|
|
||||||
|
|
||||||
def location_canonical_name(location):
|
def location_canonical_name(location):
|
||||||
|
|
@ -198,17 +204,17 @@ def location_processing(location, ip_addr):
|
||||||
full_address = geolocation['address']
|
full_address = geolocation['address']
|
||||||
else:
|
else:
|
||||||
location = NOT_FOUND_LOCATION #location[1:]
|
location = NOT_FOUND_LOCATION #location[1:]
|
||||||
try:
|
|
||||||
query_source_location = get_location(ip_addr)
|
query_source_location = None, None
|
||||||
except:
|
|
||||||
query_source_location = NOT_FOUND_LOCATION, None
|
|
||||||
|
|
||||||
country = None
|
country = None
|
||||||
if location is None or location == 'MyLocation':
|
if location is None or location == 'MyLocation':
|
||||||
|
query_source_location = get_location(ip_addr)
|
||||||
location, country = query_source_location
|
location, country = query_source_location
|
||||||
|
|
||||||
if is_ip(location):
|
if is_ip(location):
|
||||||
location, country = get_location(location)
|
location, country = get_location(location)
|
||||||
|
|
||||||
if location.startswith('@'):
|
if location.startswith('@'):
|
||||||
try:
|
try:
|
||||||
location, country = get_location(socket.gethostbyname(location[1:]))
|
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])))
|
[ip_addr, user_agent, orig_location_utf8, location_utf8, use_imperial, lang])))
|
||||||
|
|
||||||
if country and location != NOT_FOUND_LOCATION:
|
if country and location != NOT_FOUND_LOCATION:
|
||||||
location = "%s, %s" % (location, country)
|
location = "%s,%s" % (location, country)
|
||||||
|
|
||||||
# We are ready to return the answer
|
# We are ready to return the answer
|
||||||
try:
|
try:
|
||||||
if png_filename:
|
if png_filename:
|
||||||
options = {
|
options = {
|
||||||
'lang': None,
|
'lang': None,
|
||||||
'location': "%s,%s" % (location, country)}
|
'location': location}
|
||||||
options.update(query)
|
options.update(query)
|
||||||
|
|
||||||
cached_png_file = wttrin_png.make_wttr_in_png(png_filename, options=options)
|
cached_png_file = wttrin_png.make_wttr_in_png(png_filename, options=options)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue