Created
March 28, 2016 18:48
-
-
Save joebuhlig/d652e20182ed3c380e15 to your computer and use it in GitHub Desktop.
This file contains 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
function weatherLogger() { | |
var url = "http://api.wunderground.com/api/XXXXXXXXXXX/yesterday/q/STATE/CITY.json" | |
var response = UrlFetchApp.fetch(url); | |
var data = JSON.parse(response); | |
var summary = data.history.dailysummary[0]; | |
var slength = summary.length; | |
var newFileData = summary["date"]["pretty"] + "\n"; | |
newFileData += "\n"; | |
newFileData += "High temp: " + summary["maxtempi"]; | |
newFileData += "\n"; | |
newFileData += "Low temp: " + summary["mintempi"]; | |
newFileData += "\n"; | |
newFileData += "Avg temp: " + summary["meantempi"]; | |
newFileData += "\n"; | |
newFileData += "Rain: " + summary["rain"]; | |
newFileData += "\n"; | |
newFileData += "Snow: " + summary["snow"] + " " + summary["snowfalli"] + " " + summary["snowdepthi"]; | |
newFileData += "\n"; | |
newFileData += "Precipitation: " + summary["precipi"]; | |
newFileData += "\n"; | |
newFileData += "Growing Degree Days: " + summary["gdegreedays"]; | |
newFileData += "\n"; | |
newFileData += "Max Wind Speed: " + summary["maxwspdi"] + "mph"; | |
newFileData += "\n"; | |
newFileData += "Avg Wind Speed: " + summary["meanwindspdi"] + "mph " + summary["meanwdire"]; | |
newFileData += "\n"; | |
newFileData += "Humidity: " + summary["humidity"]; | |
newFileData += "\n"; | |
newFileData += "\n"; | |
newFileData += "Raw Data:"; | |
for (var key in summary) { | |
var dataToLog = key + ": " + JSON.stringify(summary[key]); | |
if (newFileData == "") { | |
newFileData = dataToLog; | |
} | |
else { | |
newFileData += "\n"; | |
newFileData += dataToLog; | |
}; | |
}; | |
var today = new Date(); | |
var d = new Date(today); | |
d.setDate(today.getDate() - 1); | |
var y = d.getFullYear(); | |
var m = d.getMonth(); | |
m = m + 1 | |
m = "00" + m | |
m = m.substr(m.length - 2); | |
var day = d.getDate(); | |
day - 1; | |
day = "00" + day; | |
day = day.substr(day.length - 2); | |
var dateString = y + m + day; | |
DriveApp.createFile("Weatherx_Yesterdayx_" + dateString + ".txt", newFileData); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment