-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewsDataFetcher.js
More file actions
38 lines (31 loc) · 1.22 KB
/
newsDataFetcher.js
File metadata and controls
38 lines (31 loc) · 1.22 KB
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
/*
This JS file is the handles calling the New York Times API and getting the necessary data from it.
(C) Rakesh Das https://rakeshdas.com
*/
var request = require('request');
var newsApiKey = "0d58b36380f045f48f7aa174c8083ba6";
var cnnNewsUrl = "https://newsapi.org/v1/articles?source=cnn&sortBy=top&apiKey=" + newsApiKey;
var businessInsiderNewsUrl = "https://newsapi.org/v1/articles?source=business-insider&sortBy=top&apiKey=" + newsApiKey;
var apNewsUrl = "https://newsapi.org/v1/articles?source=associated-press&sortBy=top&apiKey=" + newsApiKey;
var nyTimesApiKey_DEV = "e2a3619e1d594b4f8e774a4dbb2083bf";
var nyTimesApiKey_RELEASE = "12b3c10727f9a45375d342ed28c48176:11:72542931";
var nyTimesApi = "http://api.nytimes.com/svc/topstories/v1/home.json?api-key=" + nyTimesApiKey_DEV;
var newsUrls = [cnnNewsUrl, businessInsiderNewsUrl, apNewsUrl];
var news = []; //array for news headlines and abstracts
function getNewsData() {
request({
url: nyTimesApi,
json: true
}, function (err, res, body) {
news = body.results;
return news;
});
}
module.exports = {
getNewsData: getNewsData,
news: function () {
if (news.length > 0) {
return news;
}
}
}