add weather, cpu and memory to waybar
This commit is contained in:
@@ -2,7 +2,23 @@
|
|||||||
"position": "top",
|
"position": "top",
|
||||||
"modules-left": ["hyprland/workspaces"],
|
"modules-left": ["hyprland/workspaces"],
|
||||||
"modules-center": ["hyprland/window"],
|
"modules-center": ["hyprland/window"],
|
||||||
"modules-right": ["network", "pulseaudio", "battery", "clock"],
|
"modules-right": ["custom/weather", "network", "cpu", "memory", "pulseaudio", "battery", "clock"],
|
||||||
|
"custom/weather": {
|
||||||
|
"interval": 600,
|
||||||
|
"exec": "python -O /home/frodd/.config/waybar/weather.py",
|
||||||
|
"format": "{icon} {text}",
|
||||||
|
"format_icons": {
|
||||||
|
"default": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cpu": {
|
||||||
|
"interval": 10,
|
||||||
|
"format": " {usage}%"
|
||||||
|
},
|
||||||
|
"memory": {
|
||||||
|
"interval": 30,
|
||||||
|
"format": " {used:0.1f}/{total:0.1f} ({percentage}%)"
|
||||||
|
},
|
||||||
"clock": {
|
"clock": {
|
||||||
"format": "<span foreground='#f5c2e7'> </span>{:%a %d %H:%M}",
|
"format": "<span foreground='#f5c2e7'> </span>{:%a %d %H:%M}",
|
||||||
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>"
|
"tooltip-format": "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>"
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ button:hover {
|
|||||||
background-color: #eb4d4b;
|
background-color: #eb4d4b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-weather,
|
||||||
#pulseaudio,
|
#pulseaudio,
|
||||||
#clock,
|
#clock,
|
||||||
#battery,
|
#battery,
|
||||||
@@ -66,7 +67,7 @@ button:hover {
|
|||||||
#wireplumber,
|
#wireplumber,
|
||||||
#tray,
|
#tray,
|
||||||
#network,
|
#network,
|
||||||
#mode,
|
#mode
|
||||||
#scratchpad {
|
#scratchpad {
|
||||||
margin-top: 2px;
|
margin-top: 2px;
|
||||||
margin-bottom: 2px;
|
margin-bottom: 2px;
|
||||||
@@ -76,6 +77,21 @@ button:hover {
|
|||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-weather {
|
||||||
|
color: @red;
|
||||||
|
border-bottom: 2px solid @red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#cpu {
|
||||||
|
color: @mauve;
|
||||||
|
border-bottom: 2px solid @mauve;
|
||||||
|
}
|
||||||
|
|
||||||
|
#memory {
|
||||||
|
color: @peach;
|
||||||
|
border-bottom: 2px solid @peach;
|
||||||
|
}
|
||||||
|
|
||||||
#clock {
|
#clock {
|
||||||
color: @maroon;
|
color: @maroon;
|
||||||
border-bottom: 2px solid @maroon;
|
border-bottom: 2px solid @maroon;
|
||||||
|
|||||||
86
waybar/.config/waybar/weather.py
Normal file
86
waybar/.config/waybar/weather.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
"""Small script to generate weather data."""
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class Weather:
|
||||||
|
"""Weather data is managed here."""
|
||||||
|
|
||||||
|
error_time = 0
|
||||||
|
data = {}
|
||||||
|
script_path = ''
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.script_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
self.get_weather()
|
||||||
|
|
||||||
|
def get_weather(self):
|
||||||
|
"""Retrieve current weather from weatherapi.com."""
|
||||||
|
try:
|
||||||
|
# retrieve data from json file
|
||||||
|
with open(
|
||||||
|
f"{self.script_path}/weather_settings.json",
|
||||||
|
"r",
|
||||||
|
encoding="UTF-8") as read_file:
|
||||||
|
self.data = json.load(read_file)
|
||||||
|
url = "api.weatherapi.com/v1/current.json"
|
||||||
|
key = self.data['key']
|
||||||
|
unit = "°C" if self.data['unit'] == "Celsius" else "°F"
|
||||||
|
parameters = self.data['parameters']
|
||||||
|
icon_pos = self.icon_position()
|
||||||
|
|
||||||
|
# retrieve weather from weatherapi.com
|
||||||
|
request = f"http://{url}?key={key}&q={parameters}"
|
||||||
|
response = requests.get(request)
|
||||||
|
self.data = json.loads(response.content)
|
||||||
|
temp = self.data['current']['temp_c'] if unit == "°C" \
|
||||||
|
else self.data['current']['temp_f']
|
||||||
|
# determine the icon
|
||||||
|
icon = self.get_icon()
|
||||||
|
|
||||||
|
# display weather
|
||||||
|
if icon_pos == "left":
|
||||||
|
print(f"{icon} {int(round(temp))}{unit}")
|
||||||
|
else:
|
||||||
|
print(f"{int(round(temp))}{unit} {icon} ")
|
||||||
|
except requests.ConnectionError:
|
||||||
|
self.error_handling()
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
print("error in weather_settings.json file")
|
||||||
|
|
||||||
|
def error_handling(self):
|
||||||
|
"""Handle errors."""
|
||||||
|
time.sleep(self.error_time)
|
||||||
|
self.error_time += 10
|
||||||
|
self.get_weather()
|
||||||
|
|
||||||
|
def get_icon(self):
|
||||||
|
"""Determine weather icon in function of the current\
|
||||||
|
weather conditions and hour."""
|
||||||
|
# retrieve data from json file
|
||||||
|
with open(f"{self.script_path}/weather_icons.json",
|
||||||
|
"r",
|
||||||
|
encoding="UTF-8") as read_file:
|
||||||
|
data = json.load(read_file)
|
||||||
|
# get icon
|
||||||
|
icon = ''
|
||||||
|
for item in data:
|
||||||
|
if self.data['current']['condition']['text'].lower() in (item["night"].lower(),
|
||||||
|
item["day"].lower()):
|
||||||
|
if self.data['current']['is_day'] == 1:
|
||||||
|
icon = item["icon"]
|
||||||
|
else:
|
||||||
|
icon = item["icon-night"]
|
||||||
|
return icon
|
||||||
|
|
||||||
|
def icon_position(self):
|
||||||
|
"""Determine icon position."""
|
||||||
|
if "icon-position" in self.data:
|
||||||
|
return self.data["icon-position"]
|
||||||
|
return "right"
|
||||||
|
|
||||||
|
|
||||||
|
Weather()
|
||||||
342
waybar/.config/waybar/weather_icons.json
Normal file
342
waybar/.config/waybar/weather_icons.json
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"code" : 1000,
|
||||||
|
"day" : "Sunny",
|
||||||
|
"night" : "Clear",
|
||||||
|
"icon" : "滛",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1003,
|
||||||
|
"day" : "Partly Cloudy",
|
||||||
|
"night" : "Partly Cloudy",
|
||||||
|
"icon" : "杖",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1006,
|
||||||
|
"day" : "Cloudy",
|
||||||
|
"night" : "Cloudy",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" :""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1009,
|
||||||
|
"day" : "Overcast",
|
||||||
|
"night" : "Overcast",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1030,
|
||||||
|
"day" : "Mist",
|
||||||
|
"night" : "Mist",
|
||||||
|
"icon" : "敖",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1063,
|
||||||
|
"day" : "Patchy rain possible",
|
||||||
|
"night" : "Patchy rain possible",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1066,
|
||||||
|
"day" : "Patchy snow possible",
|
||||||
|
"night" : "Patchy snow possible",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1069,
|
||||||
|
"day" : "Patchy sleet possible",
|
||||||
|
"night" : "Patchy sleet possible",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1072,
|
||||||
|
"day" : "Patchy freezing drizzle possible",
|
||||||
|
"night" : "Patchy freezing drizzle possible",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1087,
|
||||||
|
"day" : "Thundery outbreaks possible",
|
||||||
|
"night" : "Thundery outbreaks possible",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1114,
|
||||||
|
"day" : "Blowing snow",
|
||||||
|
"night" : "Blowing snow",
|
||||||
|
"icon" : "ﭽ",
|
||||||
|
"icon-night" : "ﭽ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1117,
|
||||||
|
"day" : "Blizzard",
|
||||||
|
"night" : "Blizzard",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1135,
|
||||||
|
"day" : "Fog",
|
||||||
|
"night" : "Fog",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1147,
|
||||||
|
"day" : "Freezing fog",
|
||||||
|
"night" : "Freezing fog",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1150,
|
||||||
|
"day" : "Patchy light drizzle",
|
||||||
|
"night" : "Patchy light drizzle",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1153,
|
||||||
|
"day" : "Light drizzle",
|
||||||
|
"night" : "Light drizzle",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1168,
|
||||||
|
"day" : "Freezing drizzle",
|
||||||
|
"night" : "Freezing drizzle",
|
||||||
|
"icon" : "ﭽ",
|
||||||
|
"icon-night" : "ﭽ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1171,
|
||||||
|
"day" : "Heavy freezing drizzle",
|
||||||
|
"night" : "Heavy freezing drizzle",
|
||||||
|
"icon" : "ﭽ",
|
||||||
|
"icon-night" : "ﭽ"
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1180,
|
||||||
|
"day" : "Patchy light rain",
|
||||||
|
"night" : "Patchy light rain",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1183,
|
||||||
|
"day" : "Light rain",
|
||||||
|
"night" : "Light rain",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1186,
|
||||||
|
"day" : "Moderate rain at times",
|
||||||
|
"night" : "Moderate rain at times",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1189,
|
||||||
|
"day" : "Moderate rain",
|
||||||
|
"night" : "Moderate rain",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1192,
|
||||||
|
"day" : "Heavy rain at times",
|
||||||
|
"night" : "Heavy rain at times",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1195,
|
||||||
|
"day" : "Heavy rain",
|
||||||
|
"night" : "Heavy rain",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1198,
|
||||||
|
"day" : "Light freezing rain",
|
||||||
|
"night" : "Light freezing rain",
|
||||||
|
"icon" : "ﭽ",
|
||||||
|
"icon-night" : "ﭽ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1201,
|
||||||
|
"day" : "Moderate or heavy freezing rain",
|
||||||
|
"night" : "Moderate or heavy freezing rain",
|
||||||
|
"icon" : "ﭽ",
|
||||||
|
"icon-night" : "ﭽ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1204,
|
||||||
|
"day" : "Light sleet",
|
||||||
|
"night" : "Light sleet",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1207,
|
||||||
|
"day" : "Moderate or heavy sleet",
|
||||||
|
"night" : "Moderate or heavy sleet",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1210,
|
||||||
|
"day" : "Patchy light snow",
|
||||||
|
"night" : "Patchy light snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1213,
|
||||||
|
"day" : "Light snow",
|
||||||
|
"night" : "Light snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1216,
|
||||||
|
"day" : "Patchy moderate snow",
|
||||||
|
"night" : "Patchy moderate snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1219,
|
||||||
|
"day" : "Moderate snow",
|
||||||
|
"night" : "Moderate snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1222,
|
||||||
|
"day" : "Patchy heavy snow",
|
||||||
|
"night" : "Patchy heavy snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1225,
|
||||||
|
"day" : "Heavy snow",
|
||||||
|
"night" : "Heavy snow",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1237,
|
||||||
|
"day" : "Ice pellets",
|
||||||
|
"night" : "Ice pellets",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1240,
|
||||||
|
"day" : "Light rain shower",
|
||||||
|
"night" : "Light rain shower",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1243,
|
||||||
|
"day" : "Moderate or heavy rain shower",
|
||||||
|
"night" : "Moderate or heavy rain shower",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1246,
|
||||||
|
"day" : "Torrential rain shower",
|
||||||
|
"night" : "Torrential rain shower",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1249,
|
||||||
|
"day" : "Light sleet showers",
|
||||||
|
"night" : "Light sleet showers",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1252,
|
||||||
|
"day" : "Moderate or heavy sleet showers",
|
||||||
|
"night" : "Moderate or heavy sleet showers",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1255,
|
||||||
|
"day" : "Light snow showers",
|
||||||
|
"night" : "Light snow showers",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1258,
|
||||||
|
"day" : "Moderate or heavy snow showers",
|
||||||
|
"night" : "Moderate or heavy snow showers",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1261,
|
||||||
|
"day" : "Light showers of ice pellets",
|
||||||
|
"night" : "Light showers of ice pellets",
|
||||||
|
"icon" : "晴",
|
||||||
|
"icon-night" : "晴"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1264,
|
||||||
|
"day" : "Moderate or heavy showers of ice pellets",
|
||||||
|
"night" : "Moderate or heavy showers of ice pellets",
|
||||||
|
"icon" : "晴",
|
||||||
|
"icon-night" : "晴"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1273,
|
||||||
|
"day" : "Patchy light rain with thunder",
|
||||||
|
"night" : "Patchy light rain with thunder",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1276,
|
||||||
|
"day" : "Moderate or heavy rain with thunder",
|
||||||
|
"night" : "Moderate or heavy rain with thunder",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1279,
|
||||||
|
"day" : "Patchy light snow with thunder",
|
||||||
|
"night" : "Patchy light snow with thunder",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" : ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"code" : 1282,
|
||||||
|
"day" : "Moderate or heavy snow with thunder",
|
||||||
|
"night" : "Moderate or heavy snow with thunder",
|
||||||
|
"icon" : "",
|
||||||
|
"icon-night" :""
|
||||||
|
}
|
||||||
|
]
|
||||||
5
waybar/.config/waybar/weather_settings.json
Normal file
5
waybar/.config/waybar/weather_settings.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"key": "ca9f34fa929b4079850204607250309",
|
||||||
|
"parameters": "Lewisham,London",
|
||||||
|
"unit": "Celsius"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user