mirror of
https://github.com/streetturtle/awesome-wm-widgets.git
synced 2024-11-17 07:49:09 +01:00
weather widget
This commit is contained in:
parent
adfcec4068
commit
1e540af00b
6 changed files with 97 additions and 1 deletions
|
@ -7,6 +7,7 @@ Set of super simple widgets compatible with Awesome Window Manager v.4.
|
||||||
From left to right:
|
From left to right:
|
||||||
|
|
||||||
- [spotify-widget](https://github.com/streetturtle/AwesomeWM/tree/master/spotify-widget) / [rhythmbox-widget](https://github.com/streetturtle/AwesomeWM/tree/master/rhythmbox-widget)
|
- [spotify-widget](https://github.com/streetturtle/AwesomeWM/tree/master/spotify-widget) / [rhythmbox-widget](https://github.com/streetturtle/AwesomeWM/tree/master/rhythmbox-widget)
|
||||||
|
- [weather-widget](https://github.com/streetturtle/AwesomeWM/tree/master/weather-widget)
|
||||||
- [email-widget](https://github.com/streetturtle/AwesomeWM/tree/master/email-widget)
|
- [email-widget](https://github.com/streetturtle/AwesomeWM/tree/master/email-widget)
|
||||||
- [brightness-widget](https://github.com/streetturtle/AwesomeWM/tree/master/brightness-widget)
|
- [brightness-widget](https://github.com/streetturtle/AwesomeWM/tree/master/brightness-widget)
|
||||||
- [volume-widget](https://github.com/streetturtle/AwesomeWM/tree/master/volume-widget)
|
- [volume-widget](https://github.com/streetturtle/AwesomeWM/tree/master/volume-widget)
|
||||||
|
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 11 KiB |
|
@ -1,6 +1,7 @@
|
||||||
# Volume widget
|
# Volume widget
|
||||||
|
|
||||||
Simple and easy-to-install widget for Awesome Window Manager which represents the sound level: ![Volume Wiget](./vol-widget-1.png)
|
Simple and easy-to-install widget for Awesome Window Manager which represents the sound level: ![Volume Widget](
|
||||||
|
./vol-widget-1.png)
|
||||||
|
|
||||||
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||||
|
|
||||||
|
|
15
weather-widget/README.md
Normal file
15
weather-widget/README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Weather widget
|
||||||
|
|
||||||
|
![Weather Widget](./weather-widget.png)
|
||||||
|
|
||||||
|
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
- install lua socket
|
||||||
|
```bash
|
||||||
|
$ sudo apt-get install luasockets
|
||||||
|
```
|
||||||
|
|
||||||
|
- download json parser for lua: https://github.com/rxi/json.lua
|
||||||
|
- get Open Weather Map app id here: https://openweathermap.org/appid
|
BIN
weather-widget/weather-widget.png
Normal file
BIN
weather-widget/weather-widget.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
79
weather-widget/weather.lua
Normal file
79
weather-widget/weather.lua
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
local wibox = require("wibox")
|
||||||
|
local http = require("socket.http")
|
||||||
|
local json = require("json")
|
||||||
|
local naughty = require("naughty")
|
||||||
|
|
||||||
|
local city = "Montreal,ca"
|
||||||
|
local open_map_key = "<openWeatherMap api key>"
|
||||||
|
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
|
||||||
|
|
||||||
|
local icon_widget = wibox.widget {
|
||||||
|
{
|
||||||
|
id = "icon",
|
||||||
|
resize = false,
|
||||||
|
widget = wibox.widget.imagebox,
|
||||||
|
},
|
||||||
|
layout = wibox.container.margin(brightness_icon, 0, 0, 3),
|
||||||
|
set_image = function(self, path)
|
||||||
|
self.icon.image = path
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
local temp_widget = wibox.widget{
|
||||||
|
font = "Play 9",
|
||||||
|
widget = wibox.widget.textbox,
|
||||||
|
}
|
||||||
|
|
||||||
|
weather_widget = wibox.widget {
|
||||||
|
icon_widget,
|
||||||
|
temp_widget,
|
||||||
|
layout = wibox.layout.fixed.horizontal,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- helps to map openWeatherMap icons to Arc icons
|
||||||
|
local icon_map = {
|
||||||
|
["01d"] = "weather-clear-symbolic.svg",
|
||||||
|
["02d"] = "weather-few-clouds-symbolic.svg",
|
||||||
|
["03d"] = "weather-clouds-symbolic.svg",
|
||||||
|
["04d"] = "weather-overcast-symbolic.svg",
|
||||||
|
["09d"] = "weather-showers-scattered-symbolic.svg",
|
||||||
|
["10d"] = "weather-showers-symbolic.svg",
|
||||||
|
["11d"] = "weather-storm-symbolic.svg",
|
||||||
|
["13d"] = "weather-snow-symbolic.svg",
|
||||||
|
["50d"] = "weather-fog-symbolic.svg",
|
||||||
|
["01n"] = "weather-clear-night-symbolic.svg",
|
||||||
|
["02n"] = "weather-few-clouds-night-symbolic.svg",
|
||||||
|
["03n"] = "weather-clouds-night-symbolic.svg",
|
||||||
|
["04n"] = "weather-overcast-symbolic.svg",
|
||||||
|
["09n"] = "weather-showers-scattered-symbolic.svg",
|
||||||
|
["10n"] = "weather-showers-symbolic.svg",
|
||||||
|
["11n"] = "weather-storm-symbolic.svg",
|
||||||
|
["13n"] = "weather-snow-symbolic.svg",
|
||||||
|
["50n"] = "weather-fog-symbolic.svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- handy function to convert temperatire in Kelvin to Celcius
|
||||||
|
function to_celcius(kelvin)
|
||||||
|
return math.floor(tonumber(kelvin) - 273.15)
|
||||||
|
end
|
||||||
|
|
||||||
|
local weather_timer = timer({ timeout = 600 })
|
||||||
|
local resp
|
||||||
|
|
||||||
|
weather_timer:connect_signal("timeout", function ()
|
||||||
|
local resp_json = http.request("http://api.openweathermap.org/data/2.5/weather?q=" .. city .."&appid=" .. open_map_key)
|
||||||
|
resp = json.decode(resp_json)
|
||||||
|
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]
|
||||||
|
temp_widget:set_text(to_celcius(resp.main.temp))
|
||||||
|
end)
|
||||||
|
weather_timer:emit_signal("timeout")
|
||||||
|
|
||||||
|
weather_widget:connect_signal("mouse::enter", function()
|
||||||
|
naughty.notify{
|
||||||
|
icon = path_to_icons .. icon_map[resp.weather[1].icon],
|
||||||
|
icon_size=20,
|
||||||
|
text = '<b>Humidity:</b> ' .. resp.main.humidity .. '%<br><b>Temperature: </b>' .. to_celcius(resp.main.temp),
|
||||||
|
timeout = 5, hover_timeout = 0.5,
|
||||||
|
width = 200,
|
||||||
|
}
|
||||||
|
end)
|
Loading…
Reference in a new issue