mirror of
https://github.com/chubin/wttr.in.git
synced 2024-10-05 01:42:07 +02:00
parent
ed569540bc
commit
d551735021
@ -36,9 +36,28 @@ def get_wetter(parsed_query):
|
||||
(returncode != 0 \
|
||||
and ('Unable to find any matching weather'
|
||||
' location to the parsed_query submitted') in stderr):
|
||||
stdout, stderr, returncode = _wego_wrapper(NOT_FOUND_LOCATION, parsed_query)
|
||||
location_not_found = True
|
||||
stdout += get_message('NOT_FOUND_MESSAGE', lang)
|
||||
stdout, stderr, returncode = _wego_wrapper(DEFAULT_LOCATION, parsed_query)
|
||||
location_not_found = True
|
||||
|
||||
not_found_header = """
|
||||
>>> _ _ ___ _ _
|
||||
>>> | || | / _ \| || |
|
||||
>>> | || |_| | | | || |_
|
||||
>>> |__ _| |_| |__ _|
|
||||
>>> |_| \___/ |_|
|
||||
>>>
|
||||
>>> 404 %s: %s
|
||||
>>>
|
||||
""" % (get_message("UNKNOWN_LOCATION", lang).upper(), parsed_query['override_location_name'])
|
||||
|
||||
not_found_header = "\n".join("\033[48;5;91m" + x + " \033[0m"
|
||||
for x in not_found_header.splitlines()[1:])
|
||||
|
||||
not_found_footer = get_message('NOT_FOUND_MESSAGE', lang)
|
||||
not_found_footer = "\n".join("\033[48;5;91m " + x + " \033[0m"
|
||||
for x in not_found_footer.splitlines() if x) + "\n"
|
||||
|
||||
stdout = not_found_header + "\n----\n" + stdout + not_found_footer
|
||||
|
||||
if "\n" in stdout:
|
||||
first_line, stdout = _wego_postprocessing(location, parsed_query, stdout)
|
||||
@ -53,7 +72,10 @@ def get_wetter(parsed_query):
|
||||
def _wego_wrapper(location, parsed_query):
|
||||
|
||||
lang = parsed_query['lang']
|
||||
location_name = parsed_query['override_location_name']
|
||||
if location == DEFAULT_LOCATION:
|
||||
location_name = DEFAULT_LOCATION.capitalize()
|
||||
else:
|
||||
location_name = parsed_query['override_location_name']
|
||||
|
||||
cmd = [WEGO, '--city=%s' % location]
|
||||
|
||||
|
@ -375,6 +375,10 @@ def wttr(location, request):
|
||||
if not response:
|
||||
parsed_query = parse_request(location, request, query)
|
||||
response = _response(parsed_query, query)
|
||||
|
||||
if parsed_query["location"] == NOT_FOUND_LOCATION:
|
||||
http_code = 404
|
||||
|
||||
# pylint: disable=broad-except
|
||||
except Exception as exception:
|
||||
logging.error("Exception has occured", exc_info=1)
|
||||
|
Loading…
Reference in New Issue
Block a user