mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 12:08:47 +00:00
view=format
This commit is contained in:
parent
fb21802982
commit
71b3a70e02
5 changed files with 29 additions and 10 deletions
|
@ -31,7 +31,6 @@ def parse_query(args):
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
reserved_args = ["lang"]
|
reserved_args = ["lang"]
|
||||||
#q = "&".join(x for x in args.keys() if x not in reserved_args)
|
|
||||||
|
|
||||||
q = ""
|
q = ""
|
||||||
|
|
||||||
|
@ -86,6 +85,11 @@ def parse_query(args):
|
||||||
val = False
|
val = False
|
||||||
result[key] = val
|
result[key] = val
|
||||||
|
|
||||||
|
# currently `view` is alias for `format`
|
||||||
|
if "format" in result and not result.get("view"):
|
||||||
|
result["view"] = result["format"]
|
||||||
|
del result["format"]
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parse_wttrin_png_name(name):
|
def parse_wttrin_png_name(name):
|
||||||
|
@ -126,4 +130,9 @@ def parse_wttrin_png_name(name):
|
||||||
|
|
||||||
parsed.update(parse_query(to_be_parsed))
|
parsed.update(parse_query(to_be_parsed))
|
||||||
|
|
||||||
|
# currently `view` is alias for `format`
|
||||||
|
if "format" in parsed and not parsed.get("view"):
|
||||||
|
parsed["view"] = parsed["format"]
|
||||||
|
del parsed["format"]
|
||||||
|
|
||||||
return parsed
|
return parsed
|
||||||
|
|
|
@ -246,7 +246,7 @@ def format_weather_data(query, parsed_query, data):
|
||||||
if 'data' not in data:
|
if 'data' not in data:
|
||||||
return 'Unknown location; please try ~%s' % parsed_query["location"]
|
return 'Unknown location; please try ~%s' % parsed_query["location"]
|
||||||
|
|
||||||
format_line = query.get('format', parsed_query.get("view", ""))
|
format_line = parsed_query.get("view", "")
|
||||||
if format_line in PRECONFIGURED_FORMAT:
|
if format_line in PRECONFIGURED_FORMAT:
|
||||||
format_line = PRECONFIGURED_FORMAT[format_line]
|
format_line = PRECONFIGURED_FORMAT[format_line]
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ def jq_query(query, data_parsed):
|
||||||
# utils {{{
|
# utils {{{
|
||||||
def colorize(string, color_code, html_output=False):
|
def colorize(string, color_code, html_output=False):
|
||||||
if html_output:
|
if html_output:
|
||||||
return "<font color='red'>%s</font>" % (string)
|
return "<font color='#777777'>%s</font>" % (string)
|
||||||
else:
|
else:
|
||||||
return "\033[%sm%s\033[0m" % (color_code, string)
|
return "\033[%sm%s\033[0m" % (color_code, string)
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -551,7 +551,7 @@ def main(query, parsed_query, data):
|
||||||
<link rel="stylesheet" type="text/css" href="/files/style.css" />
|
<link rel="stylesheet" type="text/css" href="/files/style.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<img src="/{orig_location}_format=v2_text=no.png"/>
|
<img src="/{orig_location}_view=v2_text=no.png" width="592" height="532"/>
|
||||||
<pre>
|
<pre>
|
||||||
{textual_information}
|
{textual_information}
|
||||||
</pre>
|
</pre>
|
||||||
|
@ -563,7 +563,7 @@ def main(query, parsed_query, data):
|
||||||
data_parsed, geo_data, parsed_query, html_output=True))
|
data_parsed, geo_data, parsed_query, html_output=True))
|
||||||
else:
|
else:
|
||||||
output = generate_panel(data_parsed, geo_data, parsed_query)
|
output = generate_panel(data_parsed, geo_data, parsed_query)
|
||||||
if query.get('text') != "no":
|
if query.get("text") != "no" and parsed_query.get("text") != "no":
|
||||||
output += textual_information(data_parsed, geo_data, parsed_query)
|
output += textual_information(data_parsed, geo_data, parsed_query)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ def get_wetter(query, parsed_query):
|
||||||
separator = u':'
|
separator = u':'
|
||||||
|
|
||||||
if separator:
|
if separator:
|
||||||
first = first.split(separator,1)[1]
|
first = first.split(separator, 1)[1]
|
||||||
stdout = "\n".join([first.strip()] + rest) + "\n"
|
stdout = "\n".join([first.strip()] + rest) + "\n"
|
||||||
|
|
||||||
if query.get('no-terminal', False):
|
if query.get('no-terminal', False):
|
||||||
|
|
|
@ -150,7 +150,7 @@ def get_output_format(query, parsed_query):
|
||||||
Return new location (can be rewritten)
|
Return new location (can be rewritten)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if ('format' in query and not query["format"].startswith("v2")) \
|
if ('view' in query and not query["view"].startswith("v2")) \
|
||||||
or parsed_query.get("png_filename") \
|
or parsed_query.get("png_filename") \
|
||||||
or query.get('force-ansi'):
|
or query.get('force-ansi'):
|
||||||
return False
|
return False
|
||||||
|
@ -202,8 +202,11 @@ def _response(parsed_query, query, fast_mode=False):
|
||||||
# at this point, we could not handle the query fast,
|
# at this point, we could not handle the query fast,
|
||||||
# so we handle it with all available logic
|
# so we handle it with all available logic
|
||||||
|
|
||||||
|
import json
|
||||||
|
print(json.dumps(parsed_query, indent=4))
|
||||||
|
|
||||||
loc = (parsed_query['orig_location'] or "").lower()
|
loc = (parsed_query['orig_location'] or "").lower()
|
||||||
if parsed_query["view"] or 'format' in query:
|
if parsed_query.get("view"):
|
||||||
output = wttr_line(query, parsed_query)
|
output = wttr_line(query, parsed_query)
|
||||||
elif loc == 'moon' or loc.startswith('moon@'):
|
elif loc == 'moon' or loc.startswith('moon@'):
|
||||||
output = get_moon(query, parsed_query)
|
output = get_moon(query, parsed_query)
|
||||||
|
@ -236,6 +239,13 @@ def parse_request(location, request, query, fast_mode=False):
|
||||||
`request.query_string`
|
`request.query_string`
|
||||||
`query` parsed command line arguments
|
`query` parsed command line arguments
|
||||||
|
|
||||||
|
Parameters priorities (from low to high):
|
||||||
|
|
||||||
|
* HTTP-header
|
||||||
|
* Domain name
|
||||||
|
* URL
|
||||||
|
* Filename
|
||||||
|
|
||||||
Return: dictionary with parsed parameters
|
Return: dictionary with parsed parameters
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -258,7 +268,7 @@ def parse_request(location, request, query, fast_mode=False):
|
||||||
|
|
||||||
lang, _view = get_answer_language_and_view(request)
|
lang, _view = get_answer_language_and_view(request)
|
||||||
|
|
||||||
parsed_query["view"] = parsed_query.get("view", _view)
|
parsed_query["view"] = parsed_query.get("view", query.get("view", _view))
|
||||||
parsed_query["location"] = parsed_query.get("location", location)
|
parsed_query["location"] = parsed_query.get("location", location)
|
||||||
parsed_query["orig_location"] = parsed_query["location"]
|
parsed_query["orig_location"] = parsed_query["location"]
|
||||||
parsed_query["lang"] = parsed_query.get("lang", lang)
|
parsed_query["lang"] = parsed_query.get("lang", lang)
|
||||||
|
@ -289,7 +299,7 @@ def parse_request(location, request, query, fast_mode=False):
|
||||||
def wttr(location, request):
|
def wttr(location, request):
|
||||||
"""Main rendering function, it processes incoming weather queries,
|
"""Main rendering function, it processes incoming weather queries,
|
||||||
and depending on the User-Agent string and other paramters of the query
|
and depending on the User-Agent string and other paramters of the query
|
||||||
it returns output in HTMLi, ANSI or other format.
|
it returns output in HTML, ANSI or other format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _wrap_response(response_text, html_output, png_filename=None):
|
def _wrap_response(response_text, html_output, png_filename=None):
|
||||||
|
|
Loading…
Reference in a new issue