-
Notifications
You must be signed in to change notification settings - Fork 16
/
weather.lua
82 lines (73 loc) · 2.24 KB
/
weather.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local awful = require("awful")
local gears = require("gears")
local filesystem = gears.filesystem
local json = require("modules.json")
local icon_dir = filesystem.get_configuration_dir() .. "theme/icons/weather/"
local GET_FORECAST_CMD = [[bash -c "curl -s --show-error -X GET '%s'"]]
local icon_map = {
["01d"] = "weather-clear-sky",
["02d"] = "weather-few-clouds",
["04d"] = "weather-few-clouds",
["03d"] = "weather-clouds",
["09d"] = "weather-showers-scattered",
["09n"] = "weather-showers-scattered",
["10d"] = "weather-showers",
["11d"] = "weather-strom",
["13d"] = "weather-snow",
["50d"] = "weather-fog",
["01n"] = "weather-clear-night",
["02n"] = "weather-few-clouds-night",
["03n"] = "weather-clouds-night",
["04n"] = "weather-clouds-night",
["10n"] = "weather-showers",
["11n"] = "weather-strom",
["13n"] = "weather-snow",
["50n"] = "weather-fog",
}
local api_key = require("config.keys").openweatherapi
local coordinates = { "28.6446772", "77.320955" }
local show_hourly_forecast = true
local show_daily_forecast = true
local units = "metric"
local url = (
"https://api.openweathermap.org/data/2.5/onecall"
.. "?lat="
.. coordinates[1]
.. "&lon="
.. coordinates[2]
.. "&appid="
.. api_key
.. "&units="
.. units
.. "&exclude=minutely"
.. (show_hourly_forecast == false and ",hourly" or "")
.. (show_daily_forecast == false and ",daily" or "")
)
awful.widget.watch(string.format(GET_FORECAST_CMD, url), 600, function(_, stdout, stderr)
local result = json.decode(stdout)
-- Current weather setup
local out = {
desc = result.current.weather[1].description:gsub("^%l", string.upper),
humidity = result.current.humidity,
temp = math.floor(result.current.temp),
feelsLike = math.floor(result.current.feels_like),
image = icon_dir .. icon_map[result.current.weather[1].icon] .. ".svg",
hourly = {
result.hourly[1],
result.hourly[2],
result.hourly[3],
result.hourly[4],
result.hourly[5],
result.hourly[6],
},
daily = {
result.daily[1],
result.daily[2],
result.daily[3],
result.daily[4],
result.daily[5],
result.daily[6],
}
}
awesome.emit_signal("connect::weather", out)
end)