diff --git a/lib/location.py b/lib/location.py index 72cb43c..cff6d42 100644 --- a/lib/location.py +++ b/lib/location.py @@ -250,6 +250,19 @@ def is_location_blocked(location): return location is not None and location.lower() in LOCATION_BLACK_LIST +def get_hemisphere(location): + """ + Return hemisphere of the location (True = North, False = South). + Assume North and return True if location can't be found. + """ + location_string = location[0] + if location[1] is not None: + location_string += ",%s" % location[1] + geolocation = geolocator(location_string) + if geolocation is None: + return True + return geolocation["latitude"] > 0 + def location_processing(location, ip_addr): """ """ @@ -281,6 +294,12 @@ def location_processing(location, ip_addr): query_source_location = get_location(ip_addr) + # For moon queries, hemisphere must be found + # True for North, False for South + hemisphere = False + if location is not None and (location.lower()+"@").startswith("moon@"): + hemisphere = get_hemisphere(query_source_location) + country = None if not location or location == 'MyLocation': location = ip_addr @@ -331,4 +350,5 @@ def location_processing(location, ip_addr): override_location_name, \ full_address, \ country, \ - query_source_location + query_source_location, \ + hemisphere diff --git a/lib/view/moon.py b/lib/view/moon.py index 8fc8c18..05398a1 100644 --- a/lib/view/moon.py +++ b/lib/view/moon.py @@ -15,6 +15,7 @@ def get_moon(parsed_query): location = parsed_query['orig_location'] html = parsed_query['html_output'] lang = parsed_query['lang'] + hemisphere = parsed_query['hemisphere'] date = None if '@' in location: @@ -25,6 +26,9 @@ def get_moon(parsed_query): if lang: cmd += ["-l", lang] + if not hemisphere: + cmd += ["-s", "south"] + if date: try: dateutil.parser.parse(date) diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index 8f21afe..677d61d 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -294,7 +294,7 @@ def parse_request(location, request, query, fast_mode=False): parsed_query["html_output"] = get_output_format(query, parsed_query) if not fast_mode: # not png_filename and not fast_mode: - location, override_location_name, full_address, country, query_source_location = \ + location, override_location_name, full_address, country, query_source_location, hemisphere = \ location_processing(parsed_query["location"], parsed_query["ip_addr"]) us_ip = query_source_location[1] == 'United States' \ @@ -309,7 +309,8 @@ def parse_request(location, request, query, fast_mode=False): 'override_location_name': override_location_name, 'full_address': full_address, 'country': country, - 'query_source_location': query_source_location}) + 'query_source_location': query_source_location, + 'hemisphere': hemisphere}) parsed_query.update(query) return parsed_query