Compare commits

..

No commits in common. "0d841a0c0321e4cde952c1a93dc6af6c12758c64" and "8672155b0a092e7d26654304aa35921b50417c83" have entirely different histories.

2 changed files with 105 additions and 148 deletions

View File

@ -5,7 +5,7 @@
"exclusive": true, "exclusive": true,
"passthrough": false, "passthrough": false,
"gtk-layer-shell": true, "gtk-layer-shell": true,
"height": 45, "height": 20,
"modules-left": ["clock","custom/weather","custom/wallpaper","hyprland/window"], "modules-left": ["clock","custom/weather","custom/wallpaper","hyprland/window"],
"modules-center": ["hyprland/workspaces"], "modules-center": ["hyprland/workspaces"],
"modules-right": ["network", "bluetooth", "temperature","custom/power_profile","battery","backlight","pulseaudio","pulseaudio#microphone","tray","idle_inhibitor"], "modules-right": ["network", "bluetooth", "temperature","custom/power_profile","battery","backlight","pulseaudio","pulseaudio#microphone","tray","idle_inhibitor"],
@ -43,10 +43,10 @@
"custom/power_profile": { "custom/power_profile": {
"exec": "powerprofilesctl get || echo 'Unknown'", "exec": "powerprofilesctl get",
"interval": 5, "interval": 5,
"format": "󰈐 {}", "format": "󰈐 {}",
"on-click": "pp=$(powerprofilesctl get 2>/dev/null || echo 'balanced'); case \"$pp\" in performance) n=balanced;; balanced) n=powersave;; *) n=performance;; esac; powerprofilesctl set \"$n\" 2>/dev/null || echo 'powerprofilesctl not available'; pkill -SIGRTMIN+8 waybar", "on-click": "pp=$(powerprofilesctl get); case \"$pp\" in performance) n=balanced;; balanced) n=powersave;; *) n=performance;; esac; powerprofilesctl set \"$n\"; pkill -SIGRTMIN+8 waybar",
"signal": 8, "signal": 8,
"return-type": "string" "return-type": "string"
}, },

View File

@ -2,161 +2,118 @@
import json import json
import requests import requests
import sys
from datetime import datetime from datetime import datetime
# Default fallback data WEATHER_CODES = {
data = { '113': '☀️ ',
"text": "Weather N/A", '116': '',
"tooltip": "Weather data unavailable" '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': '❄️ '
} }
try: data = {}
# Try to get weather data
response = requests.get("https://wttr.in/?format=j1", timeout=10)
response.raise_for_status() # Raise an exception for bad status codes weather = requests.get("https://wttr.in/?format=j1").json()
# Parse JSON data
weather = response.json() #Def format_time(time):
# return time.replace("00", "").zfill(2)
# Define weather codes mapping
WEATHER_CODES = {
'113': '☀️ ', def format_temp(temp):
'116': '', return (hour['FeelsLikeF']+"°").ljust(3)
'119': '☁️ ',
'122': '☁️ ',
'143': '☁️ ', def format_chances(hour):
'176': '🌧️', chances = {
'179': '🌧️', "chanceoffog": "Fog",
'182': '🌧️', "chanceoffrost": "Frost",
'185': '🌧️', "chanceofovercast": "Overcast",
'200': '⛈️ ', "chanceofrain": "Rain",
'227': '🌨️', "chanceofsnow": "Snow",
'230': '🌨️', "chanceofsunshine": "Sunshine",
'248': '☁️ ', "chanceofthunder": "Thunder",
'260': '☁️ ', "chanceofwindy": "Wind"
'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': '❄️ '
} }
def format_time(time): conditions = []
return time.replace("00", "").zfill(2) for event in chances.keys():
if int(hour[event]) > 0:
conditions.append(chances[event]+" "+hour[event]+"%")
return ", ".join(conditions)
def format_temp(temp): tempint = int(weather['current_condition'][0]['FeelsLikeF'])
return (temp+"°").ljust(3) #extrachar = ''
if tempint > 0 and tempint < 10:
extrachar = '+'
def format_chances(hour):
chances = {
"chanceoffog": "Fog",
"chanceoffrost": "Frost",
"chanceofovercast": "Overcast",
"chanceofrain": "Rain",
"chanceofsnow": "Snow",
"chanceofsunshine": "Sunshine",
"chanceofthunder": "Thunder",
"chanceofwindy": "Wind"
}
conditions = [] data['text'] = ''+WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \
for event in chances.keys(): " "+extrachar+weather['current_condition'][0]['FeelsLikeF']+"°"
if int(hour.get(event, 0)) > 0:
conditions.append(chances[event]+" "+hour.get(event, "")+"%")
return ", ".join(conditions)
# Safely extract weather data data['tooltip'] = f"<b>{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_F']}°</b>\n"
if 'current_condition' in weather and len(weather['current_condition']) > 0: data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeF']}°\n"
current = weather['current_condition'][0] data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n"
data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n"
# Extract temperature safely for i, day in enumerate(weather['weather']):
feels_like = current.get('FeelsLikeF', '0') data['tooltip'] += f"\n<b>"
tempint = int(feels_like) if feels_like.isdigit() else 0 if i == 0:
extrachar = '+' if 0 < tempint < 10 else '' data['tooltip'] += "Today, "
if i == 1:
# Build text data['tooltip'] += "Tomorrow, "
weather_code = current.get('weatherCode', '113') data['tooltip'] += f"{day['date']}</b>\n"
weather_icon = WEATHER_CODES.get(weather_code, '') data['tooltip'] += f"⬆️ {day['maxtempF']}° ⬇️ {day['mintempF']}° "
data['tooltip'] += f"🌅 {day['astronomy'][0]['sunrise']} 🌇 {day['astronomy'][0]['sunset']}\n"
data['text'] = '' + weather_icon + " " + extrachar + feels_like + "°" for hour in day['hourly']:
if i == 0:
# Build tooltip if int(format_time(hour['time'])) < datetime.now().hour-2:
data['tooltip'] = f"<b>{current.get('weatherDesc', [{'value': 'Unknown'}])[0].get('value', 'Unknown')} {current.get('temp_F', '0')}°</b>\n" continue
data['tooltip'] += f"Feels like: {feels_like}°\n" data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeF'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n"
data['tooltip'] += f"Wind: {current.get('windspeedKmph', '0')}Km/h\n"
data['tooltip'] += f"Humidity: {current.get('humidity', '0')}%\n"
# Add forecast data if available
if 'weather' in weather:
for i, day in enumerate(weather['weather']):
data['tooltip'] += f"\n<b>"
if i == 0:
data['tooltip'] += "Today, "
elif i == 1:
data['tooltip'] += "Tomorrow, "
data['tooltip'] += f"{day.get('date', '')}</b>\n"
data['tooltip'] += f"⬆️ {day.get('maxtempF', '0')}° ⬇️ {day.get('mintempF', '0')}° "
data['tooltip'] += f"🌅 {day.get('astronomy', [{}])[0].get('sunrise', '')} 🌇 {day.get('astronomy', [{}])[0].get('sunset', '')}\n"
# Hourly forecast
hourly = day.get('hourly', [])
for hour in hourly:
if i == 0:
try:
hour_time = int(format_time(hour.get('time', '0')))
if hour_time < datetime.now().hour - 2:
continue
except ValueError:
continue
data['tooltip'] += f"{format_time(hour.get('time', ''))} {WEATHER_CODES.get(hour.get('weatherCode', ''), '')} {format_temp(hour.get('FeelsLikeF', ''))} {hour.get('weatherDesc', [{'value': ''}])[0].get('value', '')}, {format_chances(hour)}\n"
else:
data['text'] = "Weather N/A"
data['tooltip'] = "Weather data unavailable"
except requests.exceptions.RequestException as e:
# Network error
data['text'] = "Weather N/A"
data['tooltip'] = f"Weather error: Network issue ({str(e)})"
except json.JSONDecodeError as e:
# JSON parsing error
data['text'] = "Weather N/A"
data['tooltip'] = f"Weather error: Invalid data ({str(e)})"
except Exception as e:
# Other errors
data['text'] = "Weather N/A"
data['tooltip'] = f"Weather error: {str(e)}"
# Output the result
print(json.dumps(data)) print(json.dumps(data))