Merge branch 'master' into async
This commit is contained in:
commit
b0b6d46937
|
@ -505,7 +505,7 @@ Supported platforms: any having Awesome and `curl` installed.
|
|||
* Argument: the ICAO station code, e.g. `"LDRI"`
|
||||
* Returns a table with string keys: `${city}`, `${wind}`, `${windmph}`,
|
||||
`${windkmh}`, `${sky}`, `${weather}`, `${tempf}`, `${tempc}`, `${humid}`,
|
||||
`${dewf}`, `${dewc}` and `${press}`
|
||||
`${dewf}`, `${dewc}` and `${press}`, `${when}`
|
||||
|
||||
### vicious.widgets.wifi
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local math = { ceil = math.ceil }
|
||||
local os = { date = os.date, difftime = os.difftime, time = os.time }
|
||||
local string = { match = string.match }
|
||||
|
||||
local spawn = require"vicious.spawn"
|
||||
|
@ -17,12 +18,22 @@ local helpers = require"vicious.helpers"
|
|||
-- vicious.widgets.weather
|
||||
local weather_all = {}
|
||||
|
||||
-- copied from http://lua-users.org/wiki/TimeZone
|
||||
local function get_timezone_offset()
|
||||
local ts = os.time()
|
||||
local utcdate = os.date("!*t", ts)
|
||||
local localdate = os.date("*t", ts)
|
||||
localdate.isdst = false -- this is the trick
|
||||
return os.difftime(os.time(localdate), os.time(utcdate))
|
||||
end
|
||||
|
||||
|
||||
-- {{{ Weather widget type
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
-- Initialize function tables
|
||||
local _weather = {
|
||||
["{city}"] = "N/A",
|
||||
["{when}"] = "N/A",
|
||||
["{wind}"] = "N/A",
|
||||
["{windmph}"] = "N/A",
|
||||
["{windkmh}"] = "N/A",
|
||||
|
@ -58,6 +69,19 @@ local function parse(stdout, stderr, exitreason, exitcode)
|
|||
_weather["{press}"] = -- Pressure in hPa
|
||||
string.match(stdout, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
|
||||
|
||||
local year, month, day, hour, min =
|
||||
string.match(stdout, "(%d%d%d%d).(%d%d).(%d%d) (%d%d)(%d%d) UTC")
|
||||
if year ~= nil then
|
||||
local utctable = {
|
||||
year = year,
|
||||
month = month,
|
||||
day = day,
|
||||
hour = hour,
|
||||
min = min,
|
||||
}
|
||||
_weather["{when}"] = os.time(utctable) + get_timezone_offset()
|
||||
end
|
||||
|
||||
-- Wind speed in km/h if MPH was available
|
||||
if _weather["{windmph}"] ~= "N/A" then
|
||||
_weather["{windmph}"] = tonumber(_weather["{windmph}"])
|
||||
|
|
Loading…
Reference in New Issue