weather: add support for dew point

Signed-off-by: Jonathan McCrohan <jmccrohan@gmail.com>
Signed-off-by: Adrian C. (anrxc) <anrxc@sysphere.org>
This commit is contained in:
Jonathan McCrohan 2013-12-15 02:48:00 +01:00 committed by Adrian C. (anrxc)
parent dc556e5415
commit 7961ca1454
2 changed files with 10 additions and 1 deletions

3
README
View File

@ -282,7 +282,8 @@ vicious.widgets.weather
- provides weather information for a requested station - provides weather information for a requested station
- takes the ICAO station code as an argument, i.e. "LDRI" - takes the ICAO station code as an argument, i.e. "LDRI"
- returns a table with string keys: {city}, {wind}, {windmph}, - returns a table with string keys: {city}, {wind}, {windmph},
{windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {press} {windkmh}, {sky}, {weather}, {tempf}, {tempc}, {humid}, {dewf},
{dewc}, {press}
vicious.widgets.date vicious.widgets.date
- provides access to os.date, with optional time formatting provided - provides access to os.date, with optional time formatting provided

View File

@ -28,6 +28,8 @@ local _weather = {
["{weather}"] = "N/A", ["{weather}"] = "N/A",
["{tempf}"] = "N/A", ["{tempf}"] = "N/A",
["{tempc}"] = "N/A", ["{tempc}"] = "N/A",
["{dewf}"] = "N/A",
["{dewc}"] = "N/A",
["{humid}"] = "N/A", ["{humid}"] = "N/A",
["{press}"] = "N/A" ["{press}"] = "N/A"
} }
@ -58,6 +60,8 @@ local function worker(format, warg)
string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"] string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"]
_weather["{tempf}"] = -- Temperature in fahrenheit _weather["{tempf}"] = -- Temperature in fahrenheit
string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"] string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"]
_weather["{dewf}"] = -- Dew Point in fahrenheit
string.match(ws, "Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{dewf}"]
_weather["{humid}"] = -- Relative humidity in percent _weather["{humid}"] = -- Relative humidity in percent
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"] string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"]
_weather["{press}"] = -- Pressure in hPa _weather["{press}"] = -- Pressure in hPa
@ -71,6 +75,10 @@ local function worker(format, warg)
if _weather["{tempf}"] ~= "N/A" then if _weather["{tempf}"] ~= "N/A" then
_weather["{tempf}"] = tonumber(_weather["{tempf}"]) _weather["{tempf}"] = tonumber(_weather["{tempf}"])
_weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9) _weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9)
end -- Dew Point in °C if °F was available
if _weather["{dewf}"] ~= "N/A" then
_weather["{dewf}"] = tonumber(_weather["{dewf}"])
_weather["{dewc}"] = math.ceil((_weather["{dewf}"] - 32) * 5/9)
end -- Capitalize some stats so they don't look so out of place end -- Capitalize some stats so they don't look so out of place
if _weather["{sky}"] ~= "N/A" then if _weather["{sky}"] ~= "N/A" then
_weather["{sky}"] = helpers.capitalize(_weather["{sky}"]) _weather["{sky}"] = helpers.capitalize(_weather["{sky}"])