Last active
November 2, 2022 08:37
-
-
Save dz0ny/014188f7392130cd07fde47be9eb35d6 to your computer and use it in GitHub Desktop.
Swiftbar ARSO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# <bitbar.title>Vreme ARSO</bitbar.title> | |
# <bitbar.version>v1.0.2</bitbar.version> | |
# <bitbar.author.github>dz0ny</bitbar.author.github> | |
import requests | |
from collections import namedtuple | |
from collections import OrderedDict | |
import base64 | |
from io import BytesIO | |
import pathlib | |
from types import SimpleNamespace | |
location = "Babno%20Polje" | |
size = 12 | |
def img(pic): | |
path = pathlib.Path.home() / ".local" / f"{pic}.b64" | |
if path.exists(): | |
return path.read_text() | |
r = requests.get(f"http://www.vreme.si/app/common/images/png/weather/{pic}.png") | |
buffered = BytesIO(r.content) | |
img_base64 = base64.b64encode(buffered.getvalue()).decode() | |
with open(path, mode='w') as f: | |
f.write(img_base64) | |
return img_base64 | |
def tt(ts): | |
return ts.split("T")[1].split("+")[0] | |
req = requests.get(f"http://www.vreme.si/api/1.0/location/?lang=sl&location={location}") | |
data = req.json(object_hook=lambda d: SimpleNamespace(**d)) | |
props = data.observation.features[0].properties | |
today = props.days[0] | |
now = today.timeline[0] | |
print(f"{now.t}°C | image={img(now.clouds_icon_wwsyn_icon)} href=https://www.vreme.si/napoved/{location}/graf webview=true webvieww=380 webviewh=580") | |
print("---") | |
print(f"{props.title} ({now.wwsyn_shortText} {now.clouds_shortText}) {now.msl}hPa - {now.pa_shortText} | href=http://www.vreme.si/napoved/{location}") | |
print(f":sunrise: {tt(today.sunrise)} :sunset: {tt(today.sunset)}") | |
print(f":wind: {now.ff_shortText} {now.ff_val}km/h") | |
print(f":drop: {now.rh_shortText} {now.rh}%") | |
print("---") | |
for c, day in enumerate(data.forecast24h.features[0].properties.days): | |
date = day.date.split("-") | |
date = f"{date[2]}.{date[1]}" | |
print(f"{date} :sun.and.horizon:{day.timeline[0].tnsyn}°C :sun.max:{day.timeline[0].txsyn}°C | image={img(day.timeline[0].clouds_icon_wwsyn_icon)} href=http://www.vreme.si/napoved/{location}/graf/{c}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment