-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (58 loc) · 1.83 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
//get the information from the nytime api
const STORE= {
searchYear: '',
searchMonth: '',
searchDay: '',
results: [],
}
function inputSearchTerms (){
$('#submit-form').submit(function(event) {
event.preventDefault();
//let inputDate = $('#date').val();
var date = new Date($('#date').val());
day = date.getDate() + 1;
month = date.getMonth() + 1;
year = date.getFullYear();
fullSearchDate = [year, month, day].join("");
console.log(fullSearchDate);
getDataFromApi(fullSearchDate, fullSearchDate, handleApiResults);
})
}
function getDataFromApi(begin_date, end_date, callback){
//inputSearchTerms();
var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";
url += '?' + $.param({
'api-key': "a2df3a93ff5541dd979083ae7243e85c",
'begin_date': begin_date,
'end_date': end_date,
});
$.ajax({
url: url,
method: 'GET',
}).done(function(result) {
console.log(result);
}).fail(function(err) {
throw err;
});
}
function handleApiResults (data){
console.log('handleApiResults ran');
/*const allPages = data.response.docs;
console.log(`${year}-${month}-${day}T00:00:00Z`);
const pageOne = allPages.map(function(page)
{if (page.pub_date == `${year}-${month}-${day}T00:00:00Z`) {
return ( `<div class="article">
<a href=${page.web_url}> ${page.headline.main}</a>
<p>${page.snippet}</p>
</div>`)
}
else {
console.log(page.pub_date);
};
});
console.log(allPages);
*/
}
//pull out only the headline, snippet, photo, and link
$(inputSearchTerms());
//$(getDataFromApi ('19720801', '19720801', handleApiResults));