-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (56 loc) · 1.73 KB
/
test.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
60
61
62
/*var getWeather = require("./index.js").getCustomRangeWeather;
var startDate = "2010-01-01";
var endDate = "2010-02-02";
var airportCode = "KPHL";
var i = 0;
var place = 1;
while (i < 100) {
getWeather(startDate, endDate, airportCode, function (meanTemp) {
console.log(place + " : " + meanTemp);
place++;
});
i++;
}*/
var csv = require('csv');
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
function temperature(time, temperature) {
this.time = time;
this.temp = temperature;
}
/*
fs.readFile('daily.csv', 'utf8', function (err, data) {
if (err) throw err;
csv.parse(data, function (err, data) {
var date = data[1][data[1].length - 1];
var weather = new Object();
function newWeather(time, temp) {
this.time = time;
this.temp = temp;
}
weather[date] = [];
for (var i = 1; i < data.length; i++) {
weather[date].push(new newWeather(data[i][0], data[i][1]))
};
//console.log(weather);
});
})*/
var url = "http://www.wunderground.com/history/airport/KAVP/2014/6/18/DailyHistory.html?format=1";
request(url, function (error, response, body) {
console.log(body);
if (!error && response.statusCode == 200) {
csv.parse(body, function (err, data) {
var date = data[1][data[1].length - 1];
var weather = new Object();
function newWeather(time, temp) {
this[time]= temp;
}
weather[date] = [];
for (var i = 1; i < data.length; i++) {
weather[date].push(new newWeather(data[i][0], data[i][1]))
};
console.log(weather);
});
}
});