Skip to content

Commit

Permalink
feat: consider day/night information
Browse files Browse the repository at this point in the history
This was highly requested. I hope I catched all cases.

Signed-off-by: André Jaenisch <[email protected]>
  • Loading branch information
Ryuno-Ki committed Oct 22, 2024
1 parent d64dd36 commit a9a33b5
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions weather-api-widget/weather.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ local weather_popup = awful.popup {

--- Maps WeatherAPI condition code to file name w/o extension
--- See https://www.weatherapi.com/docs/#weather-icons
--- Day/Night is determined at time of mapping the weather to an icon
local icon_map = {
[1000] = "clear-sky",
[1003] = "few-clouds",
Expand Down Expand Up @@ -293,8 +294,13 @@ local function worker(user_args)
forced_width = 300,
layout = wibox.layout.flex.horizontal,
update = function(self, weather)
local day_night_extension = ""
if weather.is_day then
day_night_extension = "-night"
end

self:get_children_by_id('icon')[1]:set_image(
ICONS_DIR .. icon_map[weather.condition.code] .. icons_extension)
ICONS_DIR .. icon_map[weather.condition.code] .. day_night_extension .. icons_extension)
self:get_children_by_id('temp')[1]:set_text(gen_temperature_str(weather.temp_c, '%.0f', false, units))
self:get_children_by_id('feels_like_temp')[1]:set_text(
LCLE.feels_like .. gen_temperature_str(weather.feelslike_c, '%.0f', false, units))
Expand All @@ -315,6 +321,11 @@ local function worker(user_args)
for i, day in ipairs(forecast) do
-- Free plan allows forecast for up to three days, each with hours
if i > 3 then break end
local day_night_extension = ""
if day.is_day then
day_night_extension = "-night"
end

local day_forecast = wibox.widget {
{
text = os.date('%a', tonumber(day.date_epoch)),
Expand All @@ -325,7 +336,10 @@ local function worker(user_args)
{
{
{
image = ICONS_DIR .. icon_map[day.day.condition.code] .. icons_extension,
image = ICONS_DIR
.. icon_map[day.day.condition.code]
.. day_night_extension
.. icons_extension,
resize = true,
forced_width = 48,
forced_height = 48,
Expand Down Expand Up @@ -575,7 +589,13 @@ local function worker(user_args)
widget:is_ok(true)

local result = json.decode(stdout)
widget:set_image(ICONS_DIR .. icon_map[result.current.condition.code] .. icons_extension)

local day_night_extension = ""
if result.current.is_day then
day_night_extension = "-night"
end

widget:set_image(ICONS_DIR .. icon_map[result.current.condition.code] .. day_night_extension .. icons_extension)
-- TODO: if units isn't "metric", read temp_f instead
widget:set_text(gen_temperature_str(result.current.temp_c, '%.0f', both_units_widget, units))

Expand Down

0 comments on commit a9a33b5

Please sign in to comment.