From 5a4c57ce96e02e2cee855dc469d186a38e4ffbf1 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Fri, 1 Feb 2019 12:29:27 +0100 Subject: [PATCH] added new option: -A (force-ansi=True) (fixes #153) --- lib/parse_query.py | 2 ++ lib/wttr_srv.py | 6 ++++-- share/help.txt | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/parse_query.py b/lib/parse_query.py index e9700d4..0cdf958 100644 --- a/lib/parse_query.py +++ b/lib/parse_query.py @@ -45,6 +45,8 @@ def parse_query(args): if q is None: return result + if 'A' in q: + result['force-ansi'] = True if 'n' in q: result['narrow'] = True if 'm' in q: diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index 51f4d2a..58ff557 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -112,7 +112,7 @@ def get_answer_language(request): return lang -def get_output_format(request): +def get_output_format(request, query): """ Return preferred output format: ansi, text, html or png based on arguments and headers in `request`. @@ -121,6 +121,8 @@ def get_output_format(request): # FIXME user_agent = request.headers.get('User-Agent', '').lower() + if query.get('force-ansi'): + return False html_output = not any(agent in user_agent for agent in PLAIN_TEXT_AGENTS) return html_output @@ -173,7 +175,7 @@ def wttr(location, request): lang = get_answer_language(request) query = parse_query.parse_query(request.args) - html_output = get_output_format(request) + html_output = get_output_format(request, query) user_agent = request.headers.get('User-Agent', '').lower() if location in PLAIN_TEXT_PAGES: diff --git a/share/help.txt b/share/help.txt index 2a6add0..f2aa7bf 100644 --- a/share/help.txt +++ b/share/help.txt @@ -29,6 +29,7 @@ View options: 0 # only current weather 1 # current weather + 1 day 2 # current weather + 2 days + A # ignore User-Agent and force ANSI output format (terminal) F # do not show the "Follow" line n # narrow version (only day and night) q # quiet version (no "Weather report" text)