-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (48 loc) · 2.47 KB
/
app.js
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
50
51
52
53
54
55
56
57
58
59
var request = require('request');
var parseString = require('xml2js').parseString;
var temp = 0;
url = 'http://www.drk7.jp/weather/xml/13.xml';
var rain =0;
request(url,function (error, response, body) {
if (!error && response.statusCode == 200) {
parseString(body, function (err, result) {
rain =result.weatherforecast.pref[0].area[3].info[0].rainfallchance[0].period[3]._;
/*
var day = result.weatherforecast.pref[0].area[3].info[0]['$'].date + "\n";
var weather = result.weatherforecast.pref[0].area[3].info[0].weather[0] + "\n";
var detail = result.weatherforecast.pref[0].area[3].info[0].weather_detail[0] + "\n";
var max = "最高気温は" + result.weatherforecast.pref[0].area[3].info[0].temperature[0].range[0]._ + "度\n";
var min = "最低気温は" + result.weatherforecast.pref[0].area[3].info[0].temperature[0].range[1]._ + "度です";
var message = "おはようございます。天気予報です\n" + day + weather + detail + max + min;
console.log(message);
*/
});
} else {
console.log(error + " : " + response);
}
});
module.exports={
getRain : function(callback){
var rain;
request(url,function (error, response, body) {
if (!error && response.statusCode == 200) {
parseString(body, function (err, result) {
rain =result.weatherforecast.pref[0].area[3].info[0].rainfallchance[0].period[3]._;
callback(null,rain);
/*
var day = result.weatherforecast.pref[0].area[3].info[0]['$'].date + "\n";
var weather = result.weatherforecast.pref[0].area[3].info[0].weather[0] + "\n";
var detail = result.weatherforecast.pref[0].area[3].info[0].weather_detail[0] + "\n";
var max = "最高気温は" + result.weatherforecast.pref[0].area[3].info[0].temperature[0].range[0]._ + "度\n";
var min = "最低気温は" + result.weatherforecast.pref[0].area[3].info[0].temperature[0].range[1]._ + "度です";
var message = "おはようございます。天気予報です\n" + day + weather + detail + max + min;
console.log(message);
*/
});
} else {
console.log(error + " : " + response);
}
});
return rain;
}
}