Created
March 28, 2016 18:49
-
-
Save joebuhlig/488a95d9072b6c8a1500 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/forecast/q/STATE/CITY.json" | |
var response = UrlFetchApp.fetch(url); | |
var weather = JSON.parse(response); | |
var summary = weather.forecast.simpleforecast.forecastday[0]; | |
var newFileData = summary["date"]["pretty"] + "\n"; | |
newFileData += "\n"; | |
newFileData += "High temp: " + summary["high"]["fahrenheit"] + "°F/" + summary["high"]["celsius"] + "°C"; | |
newFileData += "\n"; | |
newFileData += "Low temp: " + summary["low"]["fahrenheit"] + "°F/" + summary["low"]["celsius"] + "°C"; | |
newFileData += "\n"; | |
newFileData += "Conditions: " + summary["conditions"]; | |
newFileData += "\n"; | |
newFileData += "Precipitation: " + summary["qpf_allday"]["in"]; | |
newFileData += "\n"; | |
newFileData += "Snow: " + summary["snow_allday"]["in"]; | |
newFileData += "\n"; | |
newFileData += "Max Wind Speed: " + summary["maxwind"]["mph"] + "mph " + summary["maxwind"]["dir"]; | |
newFileData += "\n"; | |
newFileData += "Avg Wind Speed: " + summary["avewind"]["mph"] + "mph " + summary["avewind"]["dir"]; | |
newFileData += "\n"; | |
newFileData += "Humidity: " + summary["avehumidity"]; | |
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); | |
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 = "00" + day; | |
day = day.substr(day.length - 2); | |
var dateString = y + m + day; | |
DriveApp.createFile("Weatherx_Todayx_" + dateString + ".txt", newFileData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment