Surface {when} in local time for weather widget
Here's how I use this: local weather_widget = function( code, url, name ) local actual_widget = wibox.widget.textbox() local actual_tooltip = awful.tooltip({ objects = { actual_widget } }); actual_widget:buttons(awful.util.table.join( awful.button({}, 1, function () awful.spawn("firefox '" .. url .. os.time() .. "'") end) )) vicious.register(actual_widget, vicious.widgets.weather, function (widget, args) actual_tooltip:set_text( "City: " .. args["{city}"] .. "\nWind: " .. args["{windmph}"] .. "mph " .. "\nSky: " .. args["{sky}"] .. "\nHumidity: " .. args["{humid}"] .. "\nMeasured at: " .. os.date("%F %T", args["{when}"])) return name .. " " .. args["{tempf}"] .. "°F" end, 60 * 10, code) return actual_widget end
This commit is contained in:
parent
92a2138296
commit
cf81341fc9
|
@ -505,7 +505,7 @@ Supported platforms: any having Awesome and `curl` installed.
|
||||||
* Argument: the ICAO station code, e.g. `"LDRI"`
|
* Argument: the ICAO station code, e.g. `"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}`,
|
`${windkmh}`, `${sky}`, `${weather}`, `${tempf}`, `${tempc}`, `${humid}`,
|
||||||
`${dewf}`, `${dewc}` and `${press}`
|
`${dewf}`, `${dewc}` and `${press}`, `${when}`
|
||||||
|
|
||||||
### vicious.widgets.wifi
|
### vicious.widgets.wifi
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local math = { ceil = math.ceil }
|
local math = { ceil = math.ceil }
|
||||||
|
local os = { date = os.date, difftime = os.difftime, time = os.time }
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
|
|
||||||
local spawn = require"vicious.spawn"
|
local spawn = require"vicious.spawn"
|
||||||
|
@ -17,12 +18,22 @@ local helpers = require"vicious.helpers"
|
||||||
-- vicious.widgets.weather
|
-- vicious.widgets.weather
|
||||||
local weather_all = {}
|
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
|
-- {{{ Weather widget type
|
||||||
local function parse(stdout, stderr, exitreason, exitcode)
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
-- Initialize function tables
|
-- Initialize function tables
|
||||||
local _weather = {
|
local _weather = {
|
||||||
["{city}"] = "N/A",
|
["{city}"] = "N/A",
|
||||||
|
["{when}"] = "N/A",
|
||||||
["{wind}"] = "N/A",
|
["{wind}"] = "N/A",
|
||||||
["{windmph}"] = "N/A",
|
["{windmph}"] = "N/A",
|
||||||
["{windkmh}"] = "N/A",
|
["{windkmh}"] = "N/A",
|
||||||
|
@ -58,6 +69,19 @@ local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
_weather["{press}"] = -- Pressure in hPa
|
_weather["{press}"] = -- Pressure in hPa
|
||||||
string.match(stdout, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
|
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
|
-- Wind speed in km/h if MPH was available
|
||||||
if _weather["{windmph}"] ~= "N/A" then
|
if _weather["{windmph}"] ~= "N/A" then
|
||||||
_weather["{windmph}"] = tonumber(_weather["{windmph}"])
|
_weather["{windmph}"] = tonumber(_weather["{windmph}"])
|
||||||
|
|
Loading…
Reference in New Issue