added new option: -A (force-ansi=True) (fixes #153)

This commit is contained in:
Igor Chubin 2019-02-01 12:29:27 +01:00
parent eb64ed3b1e
commit 5a4c57ce96
3 changed files with 7 additions and 2 deletions

View file

@ -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:

View file

@ -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:

View file

@ -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)