From e6687abf13637d4e38c7525fb729fe2c84352185 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sat, 27 Oct 2018 17:14:33 +0200 Subject: [PATCH] use USCS for US-based IPs (fixes #229 #162) --- lib/location.py | 5 ++--- lib/wttr_srv.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/location.py b/lib/location.py index eb0edb9..925bc70 100644 --- a/lib/location.py +++ b/lib/location.py @@ -210,11 +210,10 @@ def location_processing(location, ip_addr): else: location = NOT_FOUND_LOCATION #location[1:] - query_source_location = None, None + query_source_location = get_location(ip_addr) 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): @@ -224,7 +223,7 @@ def location_processing(location, ip_addr): try: location, country = get_location(socket.gethostbyname(location[1:])) except: - query_source_location = NOT_FOUND_LOCATION, None + location, country = NOT_FOUND_LOCATION, None location = location_canonical_name(location) diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index e60e7ae..525f9de 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -167,7 +167,7 @@ def wttr(location, request): location, override_location_name, full_address, country, query_source_location = \ location_processing(location, ip_addr) - us_ip = query_source_location[1] == 'US' and 'slack' not in user_agent + us_ip = query_source_location[1] == 'United States' and 'slack' not in user_agent query = parse_query.metric_or_imperial(query, lang, us_ip=us_ip) # logging query