-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weather Icon / Current Temp in Panel #4
Labels
Comments
62 tasks
FWIW for anyone else here, I'm currently using Zren's other applet, Command Output, to get weather icon and temp in the panel, using DarkSky API, and my fontconfig set to fall back to Symbols Nerd Font for the icons. Here's what it looks like: And here's the script itself (depends on #!/usr/bin/env python3
import sys
from time import sleep
from plumbum.cmd import notify_send
from requests import get
from requests.exceptions import ConnectionError
from vault import DARKSKY_API_KEY, LAT, LONG
API_BASE = f'https://api.darksky.net/forecast/{DARKSKY_API_KEY}/{LAT},{LONG}'
ICONS = {
'rain': '',
'snow': '',
'sleet': '',
'clear-day': '',
'clear-night': '',
'wind': '',
'fog': '',
'cloudy': '',
'partly-cloudy-day': '',
'partly-cloudy-night': ''
}
def colorize(text, colorhex='#B8BB26'):
return f"<font color=\"#{colorhex.lstrip('#')}\">{text}</font>"
def notify():
try:
r = get(
API_BASE,
params={
'exclude': 'currently,daily,alerts,flags',
'units': 'uk2'
},
timeout=6
)
except ConnectionError as e:
notify_send('-a', "Weather", e)
else:
hourly, minutely = r.json()['hourly'], r.json()['minutely']
body = f"{minutely['summary']}\n{hourly['summary']}"
title_icon = ICONS[hourly['icon']]
summary = ""
for hour in hourly['data']:
i = ICONS[hour['icon']]
if not summary or i != summary[-1]:
summary += i
notify_send('-a', f"Weather {title_icon}", summary, body)
def display():
for attempt in range(3):
try:
r = get(
f"{API_BASE}",
params={
'exclude': 'minutely,hourly,daily,alerts,flags',
'units': 'uk2'
},
timeout=6
)
except ConnectionError:
sleep(6)
else:
current = r.json()['currently']
temp = round(current['temperature'])
icon = ICONS[current['icon']]
print(colorize(f"{temp}°{icon}"))
break
else:
print(colorize("~~~"))
if __name__ == '__main__':
if '--click' in sys.argv[1:]:
notify()
else:
display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://kde-look.org/content/show.php?content=175591&forumpage=0#c484110
The text was updated successfully, but these errors were encountered: