From fd1ea559072986a5b4bf8dddcedb68018c8330d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Mon, 1 Jan 2024 14:04:29 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20style(waybar):=20format=20weathe?= =?UTF-8?q?r=20python=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lua/plugins/extras/coding/recorder.lua | 2 +- .config/waybar/config.jsonc | 2 +- .config/waybar/scripts/weather.py | 148 ++++++++++-------- 3 files changed, 81 insertions(+), 71 deletions(-) diff --git a/.config/nvim/lua/plugins/extras/coding/recorder.lua b/.config/nvim/lua/plugins/extras/coding/recorder.lua index 21dfbfcb..a8384a79 100644 --- a/.config/nvim/lua/plugins/extras/coding/recorder.lua +++ b/.config/nvim/lua/plugins/extras/coding/recorder.lua @@ -12,7 +12,7 @@ return { { "dq", desc = "Delete All Macros" }, }, opts = { - useNerdFontsIcons = true, + useNerdFontsIcons = false, slots = { "a", "b", "c", "d" }, mapping = { startStopRecording = "q", diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index a0edf42f..be90d58b 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -55,7 +55,7 @@ }, "custom/weather": { "exec": "python3 ~/.config/waybar/scripts/weather.py", - "restart-interval": 100, + "restart-interval": 300, "return-type": "json", "on-click": "kitty --hold --class center-float wttr Alicante", "on-click-right": "kitty --hold --class center-float wttr -v2 Alicante", diff --git a/.config/waybar/scripts/weather.py b/.config/waybar/scripts/weather.py index 8e2690b8..9611b1c5 100755 --- a/.config/waybar/scripts/weather.py +++ b/.config/waybar/scripts/weather.py @@ -1,58 +1,59 @@ #!/usr/bin/env python import json -import requests from datetime import datetime +import requests + WEATHER_CODES = { - '113': '🌈', - '116': '⛅️', - '119': '☁️', - '122': '☁️', - '143': '🌫', - '176': '🌦', - '179': '🌧', - '182': '🌧', - '185': '🌧', - '200': '⛈', - '227': '🌨', - '230': '❄️', - '248': '🌫', - '260': '🌫', - '263': '🌦', - '266': '🌦', - '281': '🌧', - '284': '🌧', - '293': '🌦', - '296': '🌦', - '299': '🌧', - '302': '🌧', - '305': '🌧', - '308': '🌧', - '311': '🌧', - '314': '🌧', - '317': '🌧', - '320': '🌨', - '323': '🌨', - '326': '🌨', - '329': '❄️', - '332': '❄️', - '335': '❄️', - '338': '❄️', - '350': '🌧', - '353': '🌦', - '356': '🌧', - '359': '🌧', - '362': '🌧', - '365': '🌧', - '368': '🌨', - '371': '❄️', - '374': '🌧', - '377': '🌧', - '386': '⛈', - '389': '🌩', - '392': '⛈', - '395': '❄️' + "113": "🌈", + "116": "⛅️", + "119": "☁️", + "122": "☁️", + "143": "🌫", + "176": "🌦", + "179": "🌧", + "182": "🌧", + "185": "🌧", + "200": "⛈", + "227": "🌨", + "230": "❄️", + "248": "🌫", + "260": "🌫", + "263": "🌦", + "266": "🌦", + "281": "🌧", + "284": "🌧", + "293": "🌦", + "296": "🌦", + "299": "🌧", + "302": "🌧", + "305": "🌧", + "308": "🌧", + "311": "🌧", + "314": "🌧", + "317": "🌧", + "320": "🌨", + "323": "🌨", + "326": "🌨", + "329": "❄️", + "332": "❄️", + "335": "❄️", + "338": "❄️", + "350": "🌧", + "353": "🌦", + "356": "🌧", + "359": "🌧", + "362": "🌧", + "365": "🌧", + "368": "🌨", + "371": "❄️", + "374": "🌧", + "377": "🌧", + "386": "⛈", + "389": "🌩", + "392": "⛈", + "395": "❄️", } data = {} @@ -66,7 +67,7 @@ def format_time(time): def format_temp(temp): - return (hour['FeelsLikeC']+"°").ljust(3) + return (hour["FeelsLikeC"] + "°").ljust(3) def format_chances(hour): @@ -78,38 +79,47 @@ def format_chances(hour): "chanceofsnow": "Snow", "chanceofsunshine": "Sunshine", "chanceofthunder": "Thunder", - "chanceofwindy": "Wind" + "chanceofwindy": "Wind", } conditions = [] for event in chances.keys(): if int(hour[event]) > 0: - conditions.append(chances[event]+" "+hour[event]+"%") + conditions.append(chances[event] + " " + hour[event] + "%") return ", ".join(conditions) -data['text'] = WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \ - " "+weather['current_condition'][0]['FeelsLikeC']+"°C" +data["text"] = ( + WEATHER_CODES[weather["current_condition"][0]["weatherCode"]] + + " " + + weather["current_condition"][0]["temp_C"] + + "°C" +) -data['tooltip'] = f"{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°C\n" -data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°C\n" -data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n" -data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n" -for i, day in enumerate(weather['weather']): - data['tooltip'] += f"\n" +data[ + "tooltip" +] = f"{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°C\n" +data["tooltip"] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°C\n" +data["tooltip"] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n" +data["tooltip"] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n" +for i, day in enumerate(weather["weather"]): + data["tooltip"] += f"\n" if i == 0: - data['tooltip'] += "Today, " + data["tooltip"] += "Today, " if i == 1: - data['tooltip'] += "Tomorrow, " - data['tooltip'] += f"{day['date']}\n" - data['tooltip'] += f"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° " - data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n" - for hour in day['hourly']: + data["tooltip"] += "Tomorrow, " + data["tooltip"] += f"{day['date']}\n" + data["tooltip"] += f"⬆️ {day['maxtempC']}° ⬇️ {day['mintempC']}° " + data[ + "tooltip" + ] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n" + for hour in day["hourly"]: if i == 0: - if int(format_time(hour['time'])) < datetime.now().hour-2: + if int(format_time(hour["time"])) < datetime.now().hour - 2: continue - data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n" + data[ + "tooltip" + ] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n" print(json.dumps(data)) -