added new option: -A (force-ansi=True) (fixes #153)
This commit is contained in:
parent
eb64ed3b1e
commit
5a4c57ce96
3 changed files with 7 additions and 2 deletions
|
|
@ -45,6 +45,8 @@ def parse_query(args):
|
||||||
|
|
||||||
if q is None:
|
if q is None:
|
||||||
return result
|
return result
|
||||||
|
if 'A' in q:
|
||||||
|
result['force-ansi'] = True
|
||||||
if 'n' in q:
|
if 'n' in q:
|
||||||
result['narrow'] = True
|
result['narrow'] = True
|
||||||
if 'm' in q:
|
if 'm' in q:
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ def get_answer_language(request):
|
||||||
|
|
||||||
return lang
|
return lang
|
||||||
|
|
||||||
def get_output_format(request):
|
def get_output_format(request, query):
|
||||||
"""
|
"""
|
||||||
Return preferred output format: ansi, text, html or png
|
Return preferred output format: ansi, text, html or png
|
||||||
based on arguments and headers in `request`.
|
based on arguments and headers in `request`.
|
||||||
|
|
@ -121,6 +121,8 @@ def get_output_format(request):
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
user_agent = request.headers.get('User-Agent', '').lower()
|
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)
|
html_output = not any(agent in user_agent for agent in PLAIN_TEXT_AGENTS)
|
||||||
return html_output
|
return html_output
|
||||||
|
|
||||||
|
|
@ -173,7 +175,7 @@ def wttr(location, request):
|
||||||
|
|
||||||
lang = get_answer_language(request)
|
lang = get_answer_language(request)
|
||||||
query = parse_query.parse_query(request.args)
|
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()
|
user_agent = request.headers.get('User-Agent', '').lower()
|
||||||
|
|
||||||
if location in PLAIN_TEXT_PAGES:
|
if location in PLAIN_TEXT_PAGES:
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ View options:
|
||||||
0 # only current weather
|
0 # only current weather
|
||||||
1 # current weather + 1 day
|
1 # current weather + 1 day
|
||||||
2 # current weather + 2 days
|
2 # current weather + 2 days
|
||||||
|
A # ignore User-Agent and force ANSI output format (terminal)
|
||||||
F # do not show the "Follow" line
|
F # do not show the "Follow" line
|
||||||
n # narrow version (only day and night)
|
n # narrow version (only day and night)
|
||||||
q # quiet version (no "Weather report" text)
|
q # quiet version (no "Weather report" text)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue