+ Weather script for polybar
This commit is contained in:
parent
e27d1389b4
commit
1e88f2bc51
@ -4,6 +4,7 @@ throttle-limit = 5
|
|||||||
|
|
||||||
[bar/cute]
|
[bar/cute]
|
||||||
monitor = DP-2
|
monitor = DP-2
|
||||||
|
|
||||||
width = 100%
|
width = 100%
|
||||||
height = 27
|
height = 27
|
||||||
offset-y = 5
|
offset-y = 5
|
||||||
@ -21,6 +22,7 @@ padding-right = 2
|
|||||||
module-margin-left = 0
|
module-margin-left = 0
|
||||||
module-margin-right = 2
|
module-margin-right = 2
|
||||||
|
|
||||||
|
|
||||||
font-0 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
font-0 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
||||||
font-1 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
font-1 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
||||||
font-2 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
font-2 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
||||||
@ -28,7 +30,7 @@ font-3 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
|||||||
font-4 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
font-4 = Fixedsys Excelsior 3.01:pixelsize=12:antialias=true:autohint=true
|
||||||
|
|
||||||
modules-left = i3 title
|
modules-left = i3 title
|
||||||
modules-right = pulseaudio filesystem clock
|
modules-right = pulseaudio filesystem wttr clock
|
||||||
|
|
||||||
tray-position = right
|
tray-position = right
|
||||||
#override-redirect = true
|
#override-redirect = true
|
||||||
@ -96,6 +98,15 @@ label-mounted-padding = 2
|
|||||||
label-mounted = %mountpoint% %percentage_used% of %total%
|
label-mounted = %mountpoint% %percentage_used% of %total%
|
||||||
|
|
||||||
|
|
||||||
|
[module/wttr]
|
||||||
|
type = custom/script
|
||||||
|
exec = /home/shockrah/Rice/weather-fetch/fetch.py
|
||||||
|
interval = 3600
|
||||||
|
|
||||||
|
format-background = #155415
|
||||||
|
format-underline = #249124
|
||||||
|
format-overline = #249124
|
||||||
|
|
||||||
[module/cpu]
|
[module/cpu]
|
||||||
type = internal/cpu
|
type = internal/cpu
|
||||||
interval = 0.5
|
interval = 0.5
|
||||||
|
53
weather-fetch/fetch.py
Executable file
53
weather-fetch/fetch.py
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import json, requests, sys
|
||||||
|
|
||||||
|
class ReportErr(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Report:
|
||||||
|
def __init__(self, content: dict):
|
||||||
|
if 'current_condition' not in content:
|
||||||
|
raise ReportErr('Unable to get current_conditions from json')
|
||||||
|
|
||||||
|
# ref to inner data
|
||||||
|
target = content['current_condition'][0]
|
||||||
|
# time2fill fields
|
||||||
|
self.temp_c = int(target['temp_C'])
|
||||||
|
self.hum = int(target['humidity'])
|
||||||
|
|
||||||
|
if len(target['weatherDesc']) < 1:
|
||||||
|
self.desc = ''
|
||||||
|
else:
|
||||||
|
# fuck me this is stupid with all th eindexing
|
||||||
|
self.desc = target['weatherDesc'][0]['value']
|
||||||
|
@property
|
||||||
|
def __dict__(self):
|
||||||
|
return {
|
||||||
|
'hum': self.hum,
|
||||||
|
'temp_c': self.temp_c,
|
||||||
|
'desc': self.desc
|
||||||
|
}
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
'''
|
||||||
|
Basically just a pretty print that we use to
|
||||||
|
'''
|
||||||
|
return f"It's {self.temp_c}° @ {self.hum}% humidity Status: {self.desc}"
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
response = requests.get('http://wttr.in/?format=j1')
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
try:
|
||||||
|
report = Report(response.json())
|
||||||
|
print(report)
|
||||||
|
except ReportErr as re:
|
||||||
|
print(re, file=sys.stderr)
|
||||||
|
except Exception as e:
|
||||||
|
print('unable to decode response payload', file=sys.stderr)
|
||||||
|
print('Error caught', e, file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print('Unable to fetch data from wttr.in', file=sys.stderr)
|
Loading…
Reference in New Issue
Block a user