diff --git a/lib/parse_query.py b/lib/parse_query.py index 120e6b8..44be016 100644 --- a/lib/parse_query.py +++ b/lib/parse_query.py @@ -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 diff --git a/lib/view/line.py b/lib/view/line.py index 24ba323..52c98a2 100644 --- a/lib/view/line.py +++ b/lib/view/line.py @@ -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] diff --git a/lib/view/v2.py b/lib/view/v2.py index 8154559..c2d0707 100644 --- a/lib/view/v2.py +++ b/lib/view/v2.py @@ -91,7 +91,7 @@ def jq_query(query, data_parsed): # utils {{{ def colorize(string, color_code, html_output=False): if html_output: - return "%s" % (string) + return "%s" % (string) else: return "\033[%sm%s\033[0m" % (color_code, string) # }}} @@ -551,7 +551,7 @@ def main(query, parsed_query, data):
- +{textual_information}@@ -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 diff --git a/lib/view/wttr.py b/lib/view/wttr.py index b94de17..ccd57a0 100644 --- a/lib/view/wttr.py +++ b/lib/view/wttr.py @@ -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): diff --git a/lib/wttr_srv.py b/lib/wttr_srv.py index 3949577..be2afa6 100644 --- a/lib/wttr_srv.py +++ b/lib/wttr_srv.py @@ -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):