diff --git a/.gitignore b/.gitignore index 204da06..32bff6c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ rc.lua +vain diff --git a/yawn/README.md b/yawn/README.md new file mode 100644 index 0000000..dfa5cf0 --- /dev/null +++ b/yawn/README.md @@ -0,0 +1,85 @@ +Yahoo's Awesome (WM) Weather Notification +================================ + +Yawn is a module for Awesome WM providing brief and compact +weather notification via naughty lib and Yahoo! Weather API. + +Originally a fork of perceptive, it became a completely new module after various improvements and style changes. + +Usage +----- +Clone yawn repository into your $XDG_CONFIG_HOME/awesome (Awesome config dir). +Then, add in your rc.lua: + + require("yawn") + yawn.register(123456) + +where the function argument is so-called WOEID code of your city. +To obtain it you can google 'yahoo weather %CITYNAME%' and follow the first link. +It will look like + + http://weather.yahoo.com/united-states/california/san-diego-2487889/ + +and the last number in that link will be the ID you need. + +Default units and text widget color are Celsius and #D7D7D7, but they can be changed. +If you just want to change the color, add a second argument like this: + + yawn.register(123456, "#EEEEEE") + +if you want to set Fahrenheit units, add a third argument like this: + + yawn.register(123456, "#EEEEEE", "f") + +color argument can be *nil* if you don't want to change it. + +Finally, add yawn to your wibox of choice, for instance: + + right_layout:add(yawn.icon) + right_layout:add(yawn.widget) + +if you just want the notification attached to an existent widget, use *attach* instead: + + yawn.attach(*yourwidget*, 123456) + +or + + yawn.attach(*yourwidgetagain*, 123456, "f") + +you can also create a shortcut for the weather popup. In my rc.lua I've got this: + + awful.key({ altkey, }, "w", function () yawn.show_weather(5) end) + +where altkey is set right below modkey like this: + + altkey = "Mod1" + +so I can call the popup for 5 seconds pressing Alt+w. + +Localization +----- +The default language is English, but if you wish to have a localization, you +have to add a proper file in ``localizations``. You'll find a +template to fill in the subdirectory. + +Once you're done, rename it like your locale id, without ".utf8". In my case: + + $ lua + Lua 5.2.1 Copyright (C) 1994-2012 Lua.org, PUC-Rio + > print(os.getenv("LANG")) + it_IT.utf8 + > + +hence my file (Italian localization) has been named "it_IT". + +**NOTE:** If you create a localization, feel free to send me! I will add it. + +Screenshot +----- +![Screenshot][1] + +[1]: http://i.imgur.com/6JtjdBF.jpg + +License +----- + diff --git a/yawn/icons/00.png b/yawn/icons/00.png new file mode 100755 index 0000000..d30e120 Binary files /dev/null and b/yawn/icons/00.png differ diff --git a/yawn/icons/01.png b/yawn/icons/01.png new file mode 100755 index 0000000..aceb054 Binary files /dev/null and b/yawn/icons/01.png differ diff --git a/yawn/icons/02.png b/yawn/icons/02.png new file mode 100755 index 0000000..0a07b7b Binary files /dev/null and b/yawn/icons/02.png differ diff --git a/yawn/icons/03.png b/yawn/icons/03.png new file mode 100755 index 0000000..758b01e Binary files /dev/null and b/yawn/icons/03.png differ diff --git a/yawn/icons/04.png b/yawn/icons/04.png new file mode 100755 index 0000000..7f0d252 Binary files /dev/null and b/yawn/icons/04.png differ diff --git a/yawn/icons/05.png b/yawn/icons/05.png new file mode 100755 index 0000000..6a66140 Binary files /dev/null and b/yawn/icons/05.png differ diff --git a/yawn/icons/06.png b/yawn/icons/06.png new file mode 100755 index 0000000..c924fac Binary files /dev/null and b/yawn/icons/06.png differ diff --git a/yawn/icons/07.png b/yawn/icons/07.png new file mode 100755 index 0000000..d00552a Binary files /dev/null and b/yawn/icons/07.png differ diff --git a/yawn/icons/08.png b/yawn/icons/08.png new file mode 100755 index 0000000..3cc6665 Binary files /dev/null and b/yawn/icons/08.png differ diff --git a/yawn/icons/09.png b/yawn/icons/09.png new file mode 100755 index 0000000..d797ee9 Binary files /dev/null and b/yawn/icons/09.png differ diff --git a/yawn/icons/10.png b/yawn/icons/10.png new file mode 100755 index 0000000..cf08c5c Binary files /dev/null and b/yawn/icons/10.png differ diff --git a/yawn/icons/11.png b/yawn/icons/11.png new file mode 100755 index 0000000..30534a2 Binary files /dev/null and b/yawn/icons/11.png differ diff --git a/yawn/icons/12.png b/yawn/icons/12.png new file mode 100755 index 0000000..6223f8f Binary files /dev/null and b/yawn/icons/12.png differ diff --git a/yawn/icons/13.png b/yawn/icons/13.png new file mode 100755 index 0000000..ddcb8f3 Binary files /dev/null and b/yawn/icons/13.png differ diff --git a/yawn/icons/14.png b/yawn/icons/14.png new file mode 100755 index 0000000..8ee6a7b Binary files /dev/null and b/yawn/icons/14.png differ diff --git a/yawn/icons/15.png b/yawn/icons/15.png new file mode 100755 index 0000000..96c582e Binary files /dev/null and b/yawn/icons/15.png differ diff --git a/yawn/icons/16.png b/yawn/icons/16.png new file mode 100755 index 0000000..009039f Binary files /dev/null and b/yawn/icons/16.png differ diff --git a/yawn/icons/17.png b/yawn/icons/17.png new file mode 100755 index 0000000..5dc1356 Binary files /dev/null and b/yawn/icons/17.png differ diff --git a/yawn/icons/18.png b/yawn/icons/18.png new file mode 100755 index 0000000..bac1e7e Binary files /dev/null and b/yawn/icons/18.png differ diff --git a/yawn/icons/19.png b/yawn/icons/19.png new file mode 100755 index 0000000..d8b3673 Binary files /dev/null and b/yawn/icons/19.png differ diff --git a/yawn/icons/20.png b/yawn/icons/20.png new file mode 100755 index 0000000..22b929c Binary files /dev/null and b/yawn/icons/20.png differ diff --git a/yawn/icons/21.png b/yawn/icons/21.png new file mode 100755 index 0000000..01fcf46 Binary files /dev/null and b/yawn/icons/21.png differ diff --git a/yawn/icons/22.png b/yawn/icons/22.png new file mode 100755 index 0000000..eacc98d Binary files /dev/null and b/yawn/icons/22.png differ diff --git a/yawn/icons/23.png b/yawn/icons/23.png new file mode 100755 index 0000000..84ea140 Binary files /dev/null and b/yawn/icons/23.png differ diff --git a/yawn/icons/24.png b/yawn/icons/24.png new file mode 100755 index 0000000..d9e2745 Binary files /dev/null and b/yawn/icons/24.png differ diff --git a/yawn/icons/25.png b/yawn/icons/25.png new file mode 100755 index 0000000..9e4404d Binary files /dev/null and b/yawn/icons/25.png differ diff --git a/yawn/icons/26.png b/yawn/icons/26.png new file mode 100755 index 0000000..8fd0a5b Binary files /dev/null and b/yawn/icons/26.png differ diff --git a/yawn/icons/27.png b/yawn/icons/27.png new file mode 100755 index 0000000..9279254 Binary files /dev/null and b/yawn/icons/27.png differ diff --git a/yawn/icons/28.png b/yawn/icons/28.png new file mode 100755 index 0000000..cb803d7 Binary files /dev/null and b/yawn/icons/28.png differ diff --git a/yawn/icons/29.png b/yawn/icons/29.png new file mode 100755 index 0000000..c2e8626 Binary files /dev/null and b/yawn/icons/29.png differ diff --git a/yawn/icons/30.png b/yawn/icons/30.png new file mode 100755 index 0000000..d32ad22 Binary files /dev/null and b/yawn/icons/30.png differ diff --git a/yawn/icons/31.png b/yawn/icons/31.png new file mode 100755 index 0000000..4d6d47a Binary files /dev/null and b/yawn/icons/31.png differ diff --git a/yawn/icons/32.png b/yawn/icons/32.png new file mode 100755 index 0000000..f9f9f5d Binary files /dev/null and b/yawn/icons/32.png differ diff --git a/yawn/icons/33.png b/yawn/icons/33.png new file mode 100755 index 0000000..c74dfd1 Binary files /dev/null and b/yawn/icons/33.png differ diff --git a/yawn/icons/na.png b/yawn/icons/na.png new file mode 100755 index 0000000..62a5350 Binary files /dev/null and b/yawn/icons/na.png differ diff --git a/yawn/icons/source b/yawn/icons/source new file mode 100644 index 0000000..f3baf5d --- /dev/null +++ b/yawn/icons/source @@ -0,0 +1 @@ +http://merlinthered.deviantart.com/art/plain-weather-icons-157162192 \ No newline at end of file diff --git a/yawn/init.lua b/yawn/init.lua new file mode 100644 index 0000000..5a11404 --- /dev/null +++ b/yawn/init.lua @@ -0,0 +1,190 @@ +-- yawn, a weather notification module for Awesome WM 3.5+ + +local os = require("os") +local wibox = require("wibox") +local beautiful = require("beautiful") +local naughty = require("naughty") +local io = require("io") +local debug = require("debug") + +local string = string +local timer = timer +local print = print +local tonumber = tonumber + +module('yawn') + +local project_path = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]] +local localizations_path = project_path .. '/localizations/' +local icon_path = project_path .. 'icons/' +local api_url = 'http://weather.yahooapis.com/forecastrss' +local chosen_units = '?u=c&w=' -- default is Celsius +local weather_data = nil +local notification = nil +local city_id = nil +sky_na = icon_path .. "na.png" +local sky = nil +local chosen_color = nil +local language = string.gsub(os.getenv("LANG"), ".utf8", "") + +icon = wibox.widget.imagebox() +widget = wibox.widget.textbox() + +function execute(url, callback) + + -- Reads from url, then runs the callback function on it + + local f = io.popen("curl --connect-timeout 1 -fsm 3 '" .. url .. "'" ) + local ws = f:read("*all") + f:close() + + local execute_timer = timer({ timeout = 7 }) + execute_timer:connect_signal("timeout", function() + execute_timer:stop() + callback(ws) + end) + execute_timer:start() +end + +function fetch_weather() + execute(api_url..chosen_units..city_id, function(text) + + -- In case of no connection or invalid city ID, widgets won't display + if text == "" or text:match("City not found") + then + sky = sky_na + if text == "" then + weather_data = "Service not available at the moment." + else + weather_data = "City not found!\n" .. + "Are you sure " .. city_id .. " is your Yahoo city ID?" + end + return + end + + -- Processing raw data + weather_data = text:gsub("<.->", "") + weather_data = weather_data:match("Current Conditions:.-Full") + weather_data = weather_data:gsub("Current Conditions:.-\n", "Now: ") + weather_data = weather_data:gsub("Forecast:.-\n", "") + weather_data = weather_data:gsub("\nFull", "") + weather_data = weather_data:gsub("[\n]$", "") + weather_data = weather_data:gsub(" [-] " , ": ") + weather_data = weather_data:gsub("[.]", ",") + weather_data = weather_data:gsub("High: ", "") + weather_data = weather_data:gsub(" Low: ", " - ") + + -- Getting info for text widget + local now = weather_data:sub(weather_data:find("Now:")+5, weather_data:find("\n")-1) + local forecast = now:sub(1, now:find(",")-1) + local units = now:sub(now:find(",")+2, -2) + + -- Day/Night icon change + hour = tonumber(os.date("%H")) if hour >= 6 and hour <= 18 + then -- Day + if forecast == "Clear" or forecast == "Fair" then sky = icon_path .. "24.png" + elseif forecast == "Partly Cloudy" then sky = icon_path .. "26.png" + elseif forecast == "Mostly Cloudy" then sky = icon_path .. "20.png" + end + else -- Night + if forecast == "Clear" or forecast == "Fair" then sky = icon_path .. "23.png" + elseif forecast == "Partly Cloudy" then sky = icon_path .. "25.png" + elseif forecast == "Mostly Cloudy" then sky = icon_path .. "19.png" + end + end + + if sky == nil then + if forecast == "Cloudy" then sky = icon_path .. "18.png" + elseif forecast == "Sunny" then sky = icon_path .. "10.png" + elseif forecast == "Rain/Thunder" then sky = icon_path .. "00.png" + elseif forecast == "Light Snow Showers" then sky = icon_path .. "09.png" + elseif forecast == "Snow Flurries" or + forecast == "Blowing Snow" then sky = icon_path .. "12.png" + elseif forecast:find("Snow Showers") ~= nil or + forecast:find("Snow") ~= nil or + forecast:find("Sleet") ~= nil then sky = icon_path .. "11.png" + elseif forecast == "Mixed Rain And Snow" then sky = icon_path .. "02.png" + elseif forecast == "Mixed Rain And Sleet" then sky = icon_path .. "04.png" + elseif forecast == "Mixed Rain And Hail" then sky = icon_path .. "03.png" + elseif forecast == "Freezing Drizzle" then sky = icon_path .. "05.png" + elseif forecast == "Freezing Rain" then sky = icon_path .. "06png" + elseif forecast:find("Wind") ~= nil then sky = icon_path .. "17.png" + elseif forecast == "Heavy Snow" then sky = icon_path .. "13.png" + elseif forecast:find("Rain") ~= nil or + forecast:find("Drizzle") ~= nil then sky = icon_path .. "07.png" + elseif forecast:find("Showers") ~= nil or + forecast:find("Thunderstorm") ~= nil or + forecast:find("Thunder") ~= nil then sky = icon_path .. "08.png" + elseif forecast == "Hail" then sky = icon_path .. "14.png" + elseif forecast == "Foggy" or forecast == "Haze" then sky = icon_path .. "16.png" + else sky = sky_na + end + end + + -- Setting widgets + icon:set_image(sky) + widget:set_markup(" " .. units .. "") + + -- Localization + if language:find("en_") == nil + then + for line in io.lines(localizations_path .. language) + do + word = string.sub(line, 1, line:find("|")-1) + translation = string.sub(line, line:find("|")+1) + weather_data = string.gsub(weather_data, word, translation) + end + end + end) +end + +function remove_weather() + if notification ~= nil then + naughty.destroy(notification) + notification = nil + end +end + +function show_weather(t_out) + fetch_weather() + remove_weather() + notification = naughty.notify({ + text = weather_data, + icon = sky, + timeout = t_out, + hover_timeout = 0.5, + --fg = beautiful.fg_normal, + fg = "#D4D4D4", + bg = beautiful.bg_normal + }) +end + +function register(id, color, u) + if u == "f" then chosen_units = '?u=f&w=' end + chosen_color = color or "#d7d7d7" + city_id = id + fetch_weather() + update_timer = timer({ timeout = 600 }) + update_timer:connect_signal("timeout", function() + fetch_weather() + end) + update_timer:start() + fetch_weather() + + icon:connect_signal("mouse::enter", function() + show_weather(0) + end) + icon:connect_signal("mouse::leave", function() + remove_weather() + end) +end + +function attach(widget, id, u) + register(id, nil, u) + widget:connect_signal("mouse::enter", function() + show_weather(0) + end) + widget:connect_signal("mouse::leave", function() + remove_weather() + end) +end diff --git a/yawn/localizations/it_IT b/yawn/localizations/it_IT new file mode 100644 index 0000000..cb0a857 --- /dev/null +++ b/yawn/localizations/it_IT @@ -0,0 +1,56 @@ +Now:|Ora: +Sun:|Dom: +Mon:|Lun: +Tue:|Mar: +Wed:|Mer: +Thu:|Gio: +Fri:|Ven: +Sat:|Sab: +Mostly Sunny|Abbastanza Soleggiato +Sunny|Soleggiato +Sun|Soleggiato +Rain/Thunder|Temporali +Isolated Thunderstorms|Temporali Isolati +Scattered Thunderstorms|Temporali Sparsi +Thundershowers|Rovesci Temporaleschi +Thunderstorms|Temporali +Thunder|Temporale +AM|In Mattinata +PM|Nel Pomeriggio +Early|In Mattinata +Late|In Serata +Few|Sporadiche +Severe|Forti +Clear|Sereno +Fair|Sereno +Partly|Parzialmente +Mostly|Molto +Cloudy|Nuvoloso +Clouds|Nuvoloso +Scattered Showers|Temporali Sparsi +Light Snow Showers|Nevicate Leggere +Snow Showers|Nevicate +Heavy Snow|Forti Nevicate +Scattered Snow Showers|Nevicate Sparse +Mixed Rain And Snow|Pioggia E Neve +Mixed Rain And Sleet|Pioggia E Nevischio +Mixed Snow And Sleet|Neve E Nevischio +Mixed Rain And Hail|Pioggia E Grandine +Snow Flurries|Folate Di Neve +Blowing Snow|Neve Battente +Blowing Rain|Pioggia Battente +Heavy Rain|Forti Piogge +Freezing Rain|Pioggia Congelantesi +Showers|Piogge +Light Rain|Pioggia Leggera +Rain|Piovoso +Windy|Ventoso +Wind|Ventoso +Snow|Neve +Sleet|Nevischio +Drizzle|Pioggerella +Freezing Drizzle|Pioggerella Congelantesi +Hail|Grandine +Foggy|Nebbia +Haze|Nebbia +Light|Leggere diff --git a/yawn/localizations/localization_stub b/yawn/localizations/localization_stub new file mode 100644 index 0000000..59be2b6 --- /dev/null +++ b/yawn/localizations/localization_stub @@ -0,0 +1,56 @@ +Now:| +Sun:| +Mon:| +Tue:| +Wed:| +Thu:| +Fri:| +Sat:| +Mostly Sunny| +Sunny| +Sun| +Rain/Thunder| +Isolated Thunderstorms| +Scattered Thunderstorms| +Thundershowers| +Thunderstorms| +Thunder| +AM| +PM| +Early| +Late| +Few| +Severe| +Clear| +Fair| +Partly| +Mostly| +Cloudy| +Clouds| +Scattered Showers| +Light Snow Showers| +Snow Showers| +Heavy Snow| +Scattered Snow Showers| +Mixed Rain And Snow| +Mixed Rain And Sleet| +Mixed Snow And Sleet| +Mixed Rain And Hail| +Snow Flurries| +Blowing Snow| +Blowing Rain| +Heavy Rain| +Freezing Rain| +Showers| +Light Rain| +Rain| +Windy| +Wind| +Snow| +Sleet| +Drizzle| +Freezing Drizzle| +Hail| +Foggy| +Haze| +Light|