mirror of
https://github.com/chubin/wttr.in
synced 2025-01-12 03:58:45 +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 = {}
|
||||
|
||||
reserved_args = ["lang"]
|
||||
#q = "&".join(x for x in args.keys() if x not in reserved_args)
|
||||
|
||||
q = ""
|
||||
|
||||
|
@ -86,6 +85,11 @@ def parse_query(args):
|
|||
val = False
|
||||
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
|
||||
|
||||
def parse_wttrin_png_name(name):
|
||||
|
@ -126,4 +130,9 @@ def parse_wttrin_png_name(name):
|
|||
|
||||
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
|
||||
|
|
|
@ -246,7 +246,7 @@ def format_weather_data(query, parsed_query, data):
|
|||
if 'data' not in data:
|
||||
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:
|
||||
format_line = PRECONFIGURED_FORMAT[format_line]
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ def jq_query(query, data_parsed):
|
|||
# utils {{{
|
||||
def colorize(string, color_code, html_output=False):
|
||||
if html_output:
|
||||
return "<font color='red'>%s</font>" % (string)
|
||||
return "<font color='#777777'>%s</font>" % (string)
|
||||
else:
|
||||
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" />
|
||||
</head>
|
||||
<body>
|
||||
<img src="/{orig_location}_format=v2_text=no.png"/>
|
||||
<img src="/{orig_location}_view=v2_text=no.png" width="592" height="532"/>
|
||||
<pre>
|
||||
{textual_information}
|
||||
</pre>
|
||||
|
@ -563,7 +563,7 @@ def main(query, parsed_query, data):
|
|||
data_parsed, geo_data, parsed_query, html_output=True))
|
||||
else:
|
||||
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)
|
||||
return output
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ def get_wetter(query, parsed_query):
|
|||
separator = u':'
|
||||
|
||||
if separator:
|
||||
first = first.split(separator,1)[1]
|
||||
first = first.split(separator, 1)[1]
|
||||
stdout = "\n".join([first.strip()] + rest) + "\n"
|
||||
|
||||
if query.get('no-terminal', False):
|
||||
|
|
|
@ -150,7 +150,7 @@ def get_output_format(query, parsed_query):
|
|||
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 query.get('force-ansi'):
|
||||
return False
|
||||
|
@ -202,8 +202,11 @@ def _response(parsed_query, query, fast_mode=False):
|
|||
# at this point, we could not handle the query fast,
|
||||
# so we handle it with all available logic
|
||||
|
||||
import json
|
||||
print(json.dumps(parsed_query, indent=4))
|
||||
|
||||
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)
|
||||
elif loc == 'moon' or loc.startswith('moon@'):
|
||||
output = get_moon(query, parsed_query)
|
||||
|
@ -236,6 +239,13 @@ def parse_request(location, request, query, fast_mode=False):
|
|||
`request.query_string`
|
||||
`query` parsed command line arguments
|
||||
|
||||
Parameters priorities (from low to high):
|
||||
|
||||
* HTTP-header
|
||||
* Domain name
|
||||
* URL
|
||||
* Filename
|
||||
|
||||
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)
|
||||
|
||||
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["orig_location"] = parsed_query["location"]
|
||||
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):
|
||||
"""Main rendering function, it processes incoming weather queries,
|
||||
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):
|
||||
|
|
Loading…
Reference in a new issue