forked from gandhi-21/SBUHacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrendAPI.js
53 lines (45 loc) · 1.37 KB
/
TrendAPI.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
// API for Google trend Data
const googleTrends = require('google-trends-api');
const fs = require('fs');
// First Argument is an Object with the Parameters to search for and second Argument is the callback
var startDate = new Date('2013-09-15');
var endDate = new Date('2018-09-14');
var toSearch = {
keyword: "AMD",
startTime: startDate, // a new Date object
endTime: endDate, // a new Date object
};
googleTrends.interestOverTime(toSearch, (error, result) => {
if(error) {
console.log("Error found", error);
}
else {
// getArray(result);
// // console.log(result);
let data = JSON.parse(result)
let timeLineData = data.default.timelineData;
let trendData = []
timeLineData.forEach((element) => {
for(i = 0; i < 7; i++){
trendData.push(element.value[0])
}
})
// console.log(trendData)
// console.log(timeLineData)
fs.writeFile('Trends.txt', trendData, (err) => {
if(err) throw err;
console.log('Write Successful');
});
}
});
// function getArray (result) {
// // var val = 0; var val = 0;
// // var FinalValue = [];
// // noinspection JSAnnotator
// // result = result.default;
//
// console.log(result;
// // for (let value of result) {
// // console.log(value);
// // }
// };