aboutsummaryrefslogtreecommitdiff
path: root/widgets/weather.lua
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/weather.lua')
-rw-r--r--widgets/weather.lua63
1 files changed, 32 insertions, 31 deletions
diff --git a/widgets/weather.lua b/widgets/weather.lua
index f54fbc3..356f32f 100644
--- a/widgets/weather.lua
+++ b/widgets/weather.lua
@@ -14,11 +14,12 @@ local helpers = require("vicious.helpers")
-- Weather: provides weather information for a requested station
-module("vicious.widgets.weather")
+-- vicious.widgets.weather
+local weather = {}
-- Initialize function tables
-local weather = {
+local _weather = {
["{city}"] = "N/A",
["{wind}"] = "N/A",
["{windmph}"] = "N/A",
@@ -43,43 +44,43 @@ local function worker(format, warg)
f:close()
-- Check if there was a timeout or a problem with the station
- if ws == nil then return weather end
+ if ws == nil then return _weather end
- weather["{city}"] = -- City and/or area
- string.match(ws, "^(.+)%,.*%([%u]+%)") or weather["{city}"]
- weather["{wind}"] = -- Wind direction and degrees if available
- string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or weather["{wind}"]
- weather["{windmph}"] = -- Wind speed in MPH if available
- string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or weather["{windmph}"]
- weather["{sky}"] = -- Sky conditions if available
- string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or weather["{sky}"]
- weather["{weather}"] = -- Weather conditions if available
- string.match(ws, "Weather:[%s](.-)[%c]") or weather["{weather}"]
- weather["{tempf}"] = -- Temperature in fahrenheit
- string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or weather["{tempf}"]
- weather["{humid}"] = -- Relative humidity in percent
- string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or weather["{humid}"]
- weather["{press}"] = -- Pressure in hPa
- string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or weather["{press}"]
+ _weather["{city}"] = -- City and/or area
+ string.match(ws, "^(.+)%,.*%([%u]+%)") or _weather["{city}"]
+ _weather["{wind}"] = -- Wind direction and degrees if available
+ string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or _weather["{wind}"]
+ _weather["{windmph}"] = -- Wind speed in MPH if available
+ string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or _weather["{windmph}"]
+ _weather["{sky}"] = -- Sky conditions if available
+ string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or _weather["{sky}"]
+ _weather["{weather}"] = -- Weather conditions if available
+ string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"]
+ _weather["{tempf}"] = -- Temperature in fahrenheit
+ string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"]
+ _weather["{humid}"] = -- Relative humidity in percent
+ string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"]
+ _weather["{press}"] = -- Pressure in hPa
+ string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
-- Wind speed in km/h if MPH was available
- if weather["{windmph}"] ~= "N/A" then
- weather["{windmph}"] = tonumber(weather["{windmph}"])
- weather["{windkmh}"] = math.ceil(weather["{windmph}"] * 1.6)
+ if _weather["{windmph}"] ~= "N/A" then
+ _weather["{windmph}"] = tonumber(_weather["{windmph}"])
+ _weather["{windkmh}"] = math.ceil(_weather["{windmph}"] * 1.6)
end -- Temperature in °C if °F was available
- if weather["{tempf}"] ~= "N/A" then
- weather["{tempf}"] = tonumber(weather["{tempf}"])
- weather["{tempc}"] = math.ceil((weather["{tempf}"] - 32) * 5/9)
+ if _weather["{tempf}"] ~= "N/A" then
+ _weather["{tempf}"] = tonumber(_weather["{tempf}"])
+ _weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9)
end -- Capitalize some stats so they don't look so out of place
- if weather["{sky}"] ~= "N/A" then
- weather["{sky}"] = helpers.capitalize(weather["{sky}"])
+ if _weather["{sky}"] ~= "N/A" then
+ _weather["{sky}"] = helpers.capitalize(_weather["{sky}"])
end
- if weather["{weather}"] ~= "N/A" then
- weather["{weather}"] = helpers.capitalize(weather["{weather}"])
+ if _weather["{weather}"] ~= "N/A" then
+ _weather["{weather}"] = helpers.capitalize(_weather["{weather}"])
end
- return weather
+ return _weather
end
-- }}}
-setmetatable(_M, { __call = function(_, ...) return worker(...) end })
+return setmetatable(weather, { __call = function(_, ...) return worker(...) end })