Skip to content

Commit a9a33b5

Browse files
committed
feat: consider day/night information
This was highly requested. I hope I catched all cases. Signed-off-by: André Jaenisch <[email protected]>
1 parent d64dd36 commit a9a33b5

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

weather-api-widget/weather.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ local weather_popup = awful.popup {
6666

6767
--- Maps WeatherAPI condition code to file name w/o extension
6868
--- See https://www.weatherapi.com/docs/#weather-icons
69+
--- Day/Night is determined at time of mapping the weather to an icon
6970
local icon_map = {
7071
[1000] = "clear-sky",
7172
[1003] = "few-clouds",
@@ -293,8 +294,13 @@ local function worker(user_args)
293294
forced_width = 300,
294295
layout = wibox.layout.flex.horizontal,
295296
update = function(self, weather)
297+
local day_night_extension = ""
298+
if weather.is_day then
299+
day_night_extension = "-night"
300+
end
301+
296302
self:get_children_by_id('icon')[1]:set_image(
297-
ICONS_DIR .. icon_map[weather.condition.code] .. icons_extension)
303+
ICONS_DIR .. icon_map[weather.condition.code] .. day_night_extension .. icons_extension)
298304
self:get_children_by_id('temp')[1]:set_text(gen_temperature_str(weather.temp_c, '%.0f', false, units))
299305
self:get_children_by_id('feels_like_temp')[1]:set_text(
300306
LCLE.feels_like .. gen_temperature_str(weather.feelslike_c, '%.0f', false, units))
@@ -315,6 +321,11 @@ local function worker(user_args)
315321
for i, day in ipairs(forecast) do
316322
-- Free plan allows forecast for up to three days, each with hours
317323
if i > 3 then break end
324+
local day_night_extension = ""
325+
if day.is_day then
326+
day_night_extension = "-night"
327+
end
328+
318329
local day_forecast = wibox.widget {
319330
{
320331
text = os.date('%a', tonumber(day.date_epoch)),
@@ -325,7 +336,10 @@ local function worker(user_args)
325336
{
326337
{
327338
{
328-
image = ICONS_DIR .. icon_map[day.day.condition.code] .. icons_extension,
339+
image = ICONS_DIR
340+
.. icon_map[day.day.condition.code]
341+
.. day_night_extension
342+
.. icons_extension,
329343
resize = true,
330344
forced_width = 48,
331345
forced_height = 48,
@@ -575,7 +589,13 @@ local function worker(user_args)
575589
widget:is_ok(true)
576590

577591
local result = json.decode(stdout)
578-
widget:set_image(ICONS_DIR .. icon_map[result.current.condition.code] .. icons_extension)
592+
593+
local day_night_extension = ""
594+
if result.current.is_day then
595+
day_night_extension = "-night"
596+
end
597+
598+
widget:set_image(ICONS_DIR .. icon_map[result.current.condition.code] .. day_night_extension .. icons_extension)
579599
-- TODO: if units isn't "metric", read temp_f instead
580600
widget:set_text(gen_temperature_str(result.current.temp_c, '%.0f', both_units_widget, units))
581601

0 commit comments

Comments
 (0)