Created
November 20, 2012 23:26
-
-
Save mbmccormick/4121980 to your computer and use it in GitHub Desktop.
Remember The Milk umbrella reminder using http://webscript.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local lom = require 'lxp.lom' | |
local xpath = require 'xpath' | |
local response = http.request { | |
-- 2517274 is the WOEID for West Lafayette, IN | |
url = 'http://weather.yahooapis.com/forecastrss?w=2517274' | |
} | |
local hour = tonumber(os.date('%H')) | |
if (hour == 4) then -- 11:00pm eastern time | |
local forecast = xpath.selectNodes(lom.parse(response.content), | |
'//yweather:forecast')[1] | |
if forecast.attr.code == '0' or -- tornado | |
forecast.attr.code == '1' or -- tropical storm | |
forecast.attr.code == '2' or -- hurricane | |
forecast.attr.code == '3' or -- severe thunderstorms | |
forecast.attr.code == '4' or -- thunderstorms | |
forecast.attr.code == '5' or -- mixed rain and snow | |
forecast.attr.code == '6' or -- mixed rain and sleet | |
forecast.attr.code == '7' or -- mixed snow and sleet | |
forecast.attr.code == '8' or -- freezing drizzle | |
forecast.attr.code == '9' or -- drizzle | |
forecast.attr.code == '10' or -- freezing rain | |
forecast.attr.code == '11' or -- showers | |
forecast.attr.code == '12' or -- showers | |
forecast.attr.code == '17' or -- hail | |
forecast.attr.code == '18' or -- sleet | |
forecast.attr.code == '35' or -- mixed rain and hail | |
forecast.attr.code == '37' or -- isolated thunderstorms | |
forecast.attr.code == '38' or -- scattered thunderstorms | |
forecast.attr.code == '39' or -- scattered thunderstorms | |
forecast.attr.code == '40' or -- scattered showers | |
forecast.attr.code == '45' or -- thundershowers | |
forecast.attr.code == '47' then -- isolated thundershowers | |
local body = string.format( | |
'The forecast for today calls for %s with a high of %d degrees and a low of %d degrees.', | |
forecast.attr.text:lower(), forecast.attr.high, forecast.attr.low) | |
email.send { | |
server = 'yourserver', username = 'yourusername', password = 'yourpassword', | |
from = 'youremail', | |
to = '[email protected]', | |
subject = 'Bring an umbrella ^tomorrow at 9am', | |
text = 'Forecast\n' .. body | |
} | |
return 'Forecast for tomorrow calls for precipitation. Message sent.' | |
else | |
return 'Forecast for tomorrow does not call for precipitation.' | |
end | |
else | |
return 'It is not time yet.' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment