-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.js
58 lines (43 loc) · 5.73 KB
/
weather.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
//Dependencies
var cheerio = require('cheerio');
var request = require("request");
//var items = [19033, 19063, 19061, 19008, 19018, 19082, 19026, 19082, 19023, 19031, 19076, 19073, 19380, 19090, 19061, 19380, 19348, 19094, 19053, 19403, 19004, 19033, 19406, 19002, 19020, 19083, 19104, 18901, 19301, 19067, 19057, 18954, 19003, 19428, 19082, 19047, 19407, 19050, 19001, 19020, 19443, 19380, 19111, 19341, 19103, 18015, 19380, 18042, 19454, 19444, 18062, 19063, 18042, 19107, 18964, 19114, 19116, 19114, 19038, 18301, 19149, 18360, 19335, 19134, 18103, 19119, 18966, 19037, 19525, 19054, 18103, 19468, 19067, 19474, 19464, 19610, 19044, 19406, 19604, 19064, 19004, 19034, 19454, 17520, 18610, 19311, 19020, 19606, 19010, 19317, 19107, 19426, 19036, 19070, 19104, 19152, 19149, 19056, 18938, 19460, 19115, 19148, 19135, 19007, 18322, 19331, 18914, 19425, 19380, 19040, 19355, 19124, 19355, 19114, 19026, 19082, 18928, 19405, 19135, 19007, 18976, 18936, 19094, 19335, 18944, 19116, 19152, 19076, 19355, 19355, 19043, 19124, 19438, 19335, 19147, 19137, 19428, 19029, 19403, 19046, 19087, 19475, 17522, 19136, 19365, 19083, 18106, 19020, 19007, 19342, 18661, 19044, 18951, 19446, 19605, 17572, 19111, 19053, 19382, 19492, 19518, 19486, 19044, 19609, 18106, 18947, 19362, 19087, 19403, 19018, 19072, 19465, 18017, 19382, 18109, 8243, 8071, 8553, 8527, 8031, 8753, 8095, 8077, 8015, 8083, 8232, 8247, 7731, 8054, 8562, 8096, 8036, 8527, 8619, 8108, 8055, 8049, 8054, 8080, 8021, 8512, 8060, 8053, 8087, 8093, 8619, 8003, 8088, 8081, 8758, 8094, 8310, 8016, 8037, 8022, 8088, 8009, 8012, 8009, 8031, 8051, 8723, 8360, 7726, 8690, 8230, 8081, 8053, 8060, 8096, 8759, 8202, 8244, 8406, 8028, 8201, 8876, 8005, 8002, 8322, 8318, 8204, 8043, 8088, 8098, 8065, 8244, 8230, 8108, 8214, 8028, 8215, 8852, 8107, 8080, 8086, 8201, 8203, 8328, 8330, 8210, 8026, 8037, 8087, 8080, 21032, 21921, 21401, 21061, 21014, 21703, 21801, 21842, 21015, 21237, 21050, 21801, 20772, 21613, 20603, 21842, 21001, 20695, 21401, 21108, 20754, 21037, 21224, 20613, 21009, 21015];
//var items = [20659, 20656, 21901, 21014, 20653, 20650, 21601, 21157, 20678, 20619, 20705, 21054, 20743, 21224, 21085, 20166, 23061, 22408, 23320, 23227, 23608, 23112, 22401, 23235, 22401, 22192, 22192, 22407, 22407, 22554, 22401, 22406, 22485, 23831, 23452, 23225, 23234, 23112, 23455, 23831, 23116, 23452, 23456, 22191, 23185, 23228, 23803, 28384, 23607, 23692, 22405, 22554, 23462, 22408, 23831, 23834, 23462, 23321, 23233, 22554, 23860, 23185, 8008, 8225, 8244, 8332, 8203, 8094, 8057, 8070, 8332, 8094, 8053, 8021, 8057, 8226, 8260, 8106, 8110, 8034, 8723, 8520, 8201, 8540, 8052, 8701, 8050, 8015, 8527, 8055, 8330, 8070, 8406, 7726, 8223, 8316, 8753, 8043, 8226, 8360, 8094, 8002, 8030, 8096, 8080, 8872, 8882, 7746, 8006, 7701, 8734, 8533, 19809, 19810, 19805, 19803, 19703, 19713, 19713, 19701, 19720, 19803, 19709, 19720, 19977, 19808, 19958, 19930, 19966, 19901, 19720, 19720, 19707, 19709, 19702, 19904, 19901, 19971, 19702, 19963, 19720, 19977, 19703, 19904, 19940, 19720, 19808, 19709, 19711, 19711, 8514, 7728, 7730, 8902, 8816, 8055, 8853, 8736, 8505, 8234, 8016, 8723, 8360, 8330, 8360, 8755, 7727, 8721, 8078, 8527, 7747, 8050, 8215, 8753, 7731, 8753, 8857, 8330, 8360, 8016, 8332, 8242, 8234, 8759, 8735, 8402, 8097, 8110, 8753, 8260, 7731, 8091, 8060, 8731, 8010, 8054, 8085, 8251, 8332, 8109, 8302, 8012, 8205, 8234, 8232, 8059, 8021, 8085, 8012, 7735, 8008, 8087, 8533, 8240, 8081, 8068, 8882, 8081, 8865, 8831, 8731, 8857, 8110, 8822, 7726, 8050, 8754, 7712, 8723, 8012, 8361, 32804, 32821, 34744, 32822, 34744, 33782, 32703, 18015, 19403, 19468, 19111, 19032, 18964, 19101, 19610, 19372, 19135, 18052, 19348, 18915, 19426, 19056, 18951, 19460, 17527, 19014, 19135, 18045, 19341, 19422, 19154, 18017, 18018, 19468, 19464, 19015, 18951, 19382, 18045, 19115, 19033, 19128, 19446, 19526, 19149, 19092, 8016, 7054, 7753, 8075, 8066, 7737, 8753, 8062, 8005, 8009, 8003, 8865, 8016, 8027, 7095, 8701, 21047, 21136, 21224, 21061, 23225, 23111];
var items = [23294, 23518, 23150, 23505, 23005, 23454, 23455, 23701, 23328, 23220, 22407, 23464, 20186, 23113, 19063, 19063, 8204, 19063, 8007, 8733, 19116, 21921, 32819, 19063, 19063, 19063, 8232, 19063, 19063, 19063, 19063, 8332, 8204, 19086, 19446];
var heating_days = [];
var cooling_days = [];
function async(arg, callback) {
var url1 = 'http://www.wunderground.com/cgi-bin/findweather/hdfForecast?query=';
request(url1+items[arg], function(error, response, body) {
var href = cheerio.load(body)('section center#WX_Skin div#wuPage div#innerContent div.primeContent636 div#layerForecast div#forecast h3#fct_titlebar a').attr('href');
var arr = href.split('/');
var airportcode = arr[3];
console.log(arr[3]);
var url = 'http://www.wunderground.com/history/airport/' + airportcode + '/2012/1/1' + '/CustomHistory.html?dayend=31&monthend=12&yearend=2012&req_city=NA&req_state=NA&req_statename=NA&MR=1';
request(url, function(error, response, body) {
var temp1 = cheerio.load(body)('div.contentData table tbody tr:nth-child(6) td:nth-child(5)').text();
console.log(temp1);
heating_days[arg] = temp1;
var temp2 = cheerio.load(body)('div.contentData table tbody tr:nth-child(7) td:nth-child(5)').text();
cooling_days[arg] = temp2;
console.log(temp2);
callback();
});
});
}
function final() {
console.log('-------done-------');
console.log('heating\tcooling');
for (var i = 0; i<items.length; i++){
console.log(heating_days[i]+'\t'+ cooling_days[i]);
}
}
var count = 0;
for (var i=0; i<items.length; i++){
async(i, function(){
count ++;
if(count == items.length) {
final();
}
});
}