diff --git a/lib/location.py b/lib/location.py index 572b36d..4ceb76b 100644 --- a/lib/location.py +++ b/lib/location.py @@ -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:])) diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index a491557..e60e7ae 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -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)