1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| 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);
}
|