{"action":"created","issue":{"url":"https://api.github.com/repos/copycat-killer/lain/issues/186","repository_url":"https://api.github.com/repos/copycat-killer/lain","labels_url":"https://api.github.com/repos/copycat-killer/lain/issues/186/labels{/name}","comments_url":"https://api.github.com/repos/copycat-killer/lain/issues/186/comments","events_url":"https://api.github.com/repos/copycat-killer/lain/issues/186/events","html_url":"https://github.com/copycat-killer/lain/issues/186","id":144310949,"number":186,"title":"Notification function of weather widget is not general enough","user":{"login":"romildo","id":1217934,"avatar_url":"https://avatars.githubusercontent.com/u/1217934?v=3","gravatar_id":"","url":"https://api.github.com/users/romildo","html_url":"https://github.com/romildo","followers_url":"https://api.github.com/users/romildo/followers","following_url":"https://api.github.com/users/romildo/following{/other_user}","gists_url":"https://api.github.com/users/romildo/gists{/gist_id}","starred_url":"https://api.github.com/users/romildo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romildo/subscriptions","organizations_url":"https://api.github.com/users/romildo/orgs","repos_url":"https://api.github.com/users/romildo/repos","events_url":"https://api.github.com/users/romildo/events{/privacy}","received_events_url":"https://api.github.com/users/romildo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-29T16:04:22Z","updated_at":"2016-03-30T12:11:55Z","closed_at":null,"body":"The notification function of the weather widget accepts only four arguments: day, description, minimum temperature, and maximum temperature. It should not be limited to those information. There are many other useful information that can be interested to have in the notification, like humidity, pressure, wind speed, precipitation volume, etc. All of the those information should be available in the function.\r\n"},"comment":{"url":"https://api.github.com/repos/copycat-killer/lain/issues/comments/203400918","html_url":"https://github.com/copycat-killer/lain/issues/186#issuecomment-203400918","issue_url":"https://api.github.com/repos/copycat-killer/lain/issues/186","id":203400918,"user":{"login":"copycat-killer","id":1777696,"avatar_url":"https://avatars.githubusercontent.com/u/1777696?v=3","gravatar_id":"","url":"https://api.github.com/users/copycat-killer","html_url":"https://github.com/copycat-killer","followers_url":"https://api.github.com/users/copycat-killer/followers","following_url":"https://api.github.com/users/copycat-killer/following{/other_user}","gists_url":"https://api.github.com/users/copycat-killer/gists{/gist_id}","starred_url":"https://api.github.com/users/copycat-killer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/copycat-killer/subscriptions","organizations_url":"https://api.github.com/users/copycat-killer/orgs","repos_url":"https://api.github.com/users/copycat-killer/repos","events_url":"https://api.github.com/users/copycat-killer/events{/privacy}","received_events_url":"https://api.github.com/users/copycat-killer/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T12:11:54Z","updated_at":"2016-03-30T12:11:54Z","body":"@romildo Done, now you can grab any info from OWM API in your forecast notification.\r\n\r\nThe following example shows how to retrieve any data from [forecast16](http://openweathermap.org/forecast16) (default forecast API).\r\n\r\n```lua\r\nlocal read_pipe = require(\"lain.helpers\").read_pipe\r\n\r\nmyweather = lain.widgets.weather({\r\n    city_id = 3469058,  -- example city: Brasilia\r\n    units = \"imperial\", -- example units: Fahrenheit\r\n    notification_text_fun = function(wn)\r\n        -- time of data forecasted\r\n        local day = string.gsub(read_pipe(string.format(\"date -u -d @%d +'%%A %%d'\", -- customize date cmd here\r\n                                                        wn[\"dt\"])), \"\\n\", \"\")\r\n\r\n        -- weather condition\r\n        local desc = wn[\"weather\"][1][\"description\"]\r\n\r\n        -- temperatures, units are defined above\r\n        local tmin = math.floor(wn[\"temp\"][\"min\"])   -- min daily\r\n        local tmax = math.floor(wn[\"temp\"][\"max\"])   -- max daily\r\n        local tmor = math.floor(wn[\"temp\"][\"morn\"])  -- morning\r\n        local tday = math.floor(wn[\"temp\"][\"day\"])   -- day\r\n        local teve = math.floor(wn[\"temp\"][\"eve\"])   -- evening\r\n        local tnig = math.floor(wn[\"temp\"][\"night\"]) -- night\r\n\r\n        -- pressure, hPa\r\n        local pres = math.floor(wn[\"pressure\"])\r\n\r\n        -- humidity, %\r\n        local humi = math.floor(wn[\"humidity\"])\r\n        \r\n        -- wind speed, miles/hour if units are imperial, meter/sec otherwise \r\n        local wspe = math.floor(wn[\"speed\"])\r\n\r\n        -- wind degrees, meteorological degrees\r\n        local wdeg = math.floor(wn[\"deg\"])\r\n\r\n        -- cloudliness, %\r\n        local clou = math.floor(wn[\"clouds\"])\r\n\r\n        -- format infos as you like, HTML text markup is allowed\r\n        return string.format(\"<br><b>%s</b>: %s<br>temperatures: min %d - max %d °F<br>pressure: %d hPa<br>humidity: %d%%<br>wind: %d miles/hour at %d°<br>cloudliness: %d%%<br>\", day, desc, tmin, tmax, pres, humi, wspe, wdeg, clou)\r\n    end,\r\n    settings = function()\r\n        units = math.floor(weather_now[\"main\"][\"temp\"])\r\n        widget:set_text(\" \" .. units .. \" \")\r\n    end\r\n})\r\n```\r\n\r\n[screenshot](http://i.imgur.com/D2lJRU2.png) (don't care about my Italian `date`, that it's just my machine localization)\r\n\r\nThis other example shows how to retrieve any data from [forecast5](http://openweathermap.org/forecast5) instead.\r\n\r\n```lua\r\nlocal read_pipe = require(\"lain.helpers\").read_pipe\r\n\r\nmyweather = lain.widgets.weather({\r\n    city_id = 3469058,  -- example city: Brasilia\r\n    units = \"imperial\", -- example units: Fahrenheit\r\n    forecast_call = \"curl -s 'http://api.openweathermap.org/data/2.5/forecast?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'\",\r\n    notification_text_fun = function(wn)\r\n        -- every data is supposed to be valid at the moment of calculation (see dt_txt below)\r\n\r\n        -- time of data forecasted\r\n        local day = string.gsub(read_pipe(string.format(\"date -u -d @%d +'%%A %%d'\", -- customize date cmd here\r\n                                                        wn[\"dt\"])), \"\\n\", \"\")\r\n\r\n        -- weather condition\r\n        local desc = wn[\"weather\"][1][\"description\"]\r\n\r\n        -- temperatures, units are defined above\r\n        local temp = math.floor(wn[\"main\"][\"temp\"])     -- temp now\r\n        local tmin = math.floor(wn[\"main\"][\"temp_min\"]) -- current min\r\n        local tmax = math.floor(wn[\"main\"][\"temp_max\"]) -- current max\r\n\r\n        -- pressure, hPa\r\n        local pres = math.floor(wn[\"main\"][\"pressure\"])   -- sea level by default\r\n        local pres = math.floor(wn[\"main\"][\"sea_level\"])  -- sea level\r\n        local pres = math.floor(wn[\"main\"][\"grnd_level\"]) -- ground level\r\n\r\n        -- humidity, %\r\n        local humi = math.floor(wn[\"main\"][\"humidity\"])\r\n\r\n        -- wind speed, miles/hour if units are imperial, meter/sec otherwise\r\n        local wspe = math.floor(wn[\"wind\"][\"speed\"])\r\n\r\n        -- wind degrees, meteorological degrees\r\n        local wdeg = math.floor(wn[\"wind\"][\"deg\"])\r\n\r\n        -- cloudliness, %\r\n        local clou = math.floor(wn[\"clouds\"][\"all\"])\r\n\r\n        -- rain volume for last 3 hours, mm\r\n        if wn[\"rain\"] then\r\n            local rain3h = math.floor(wn[\"rain\"][\"3h\"])\r\n        else\r\n            local rain3h = 0\r\n        end\r\n\r\n        -- snow volume for last 3 hours, mm\r\n        if wn[\"snow\"] then\r\n            local snow3h = math.floor(wn[\"snow\"][\"3h\"])\r\n        else\r\n            local snow3h = 0\r\n        end\r\n\r\n        local tcalc = wn[\"dt_txt\"]\r\n\r\n        -- format infos as you like, html text markup is allowed\r\n        return string.format(\"<br><b>%s</b>: %s<br>temperatures: min %d - max %d °F<br>pressure: %d hPa<br>humidity: %d%%<br>wind: %d miles/hour at %d°<br>cloudliness: %d%%<br>\", day, desc, tmin, tmax, pres, humi, wspe, wdeg, clou)\r\n    end,\r\n    settings = function()\r\n        units = math.floor(weather_now[\"main\"][\"temp\"])\r\n        widget:set_text(\" \" .. units .. \" \")\r\n    end\r\n})\r\n```"}}