From 83b1fd45f24a29d3306ef7269b326cf7091feb88 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Tue, 23 Apr 2019 16:44:41 +0200 Subject: [PATCH] new option: C (Weather condition textual name) --- README.md | 1 + lib/wttr_line.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index a002a0f..2ed9403 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ To specify your own custom output format, use the special `%`-notation: ``` c Weather condition, + C Weather condition textual name, h Humidity, t Temperature, w Wind, diff --git a/lib/wttr_line.py b/lib/wttr_line.py index 8b3fe47..7db0c78 100644 --- a/lib/wttr_line.py +++ b/lib/wttr_line.py @@ -59,6 +59,26 @@ def render_condition(data, query): weather_condition = WEATHER_SYMBOL[WWO_CODE[data['weatherCode']]] return weather_condition +def render_condition_fullname(data, query): + """ + condition_fullname (C) + """ + + found = None + for key, val in data.items(): + if key.startswith('lang_'): + found = val + break + if not found: + found = data['weatherDesc'] + + try: + weather_condition = found[0]['value'] + except KeyError: + weather_condition = '' + + return weather_condition + def render_humidity(data, query): """ humidity (h) @@ -138,6 +158,7 @@ def render_sunset(data, query): FORMAT_SYMBOL = { 'c': render_condition, + 'C': render_condition_fullname, 'h': render_humidity, 't': render_temperature, 'w': render_wind,