let articleObjs = []; let counter = 0;
function preload() { let howmany = 10; // total article num = howmany * 10; let q = "Hypersexualization"; // CHANGE THIS TO YOUR KEYWORD //let begin = "20120101"; //let end = "20121231"; let d = 2021; //change ro the year searching let apikey = "KvyejsSIiBTC3ZS8L3L8BkwH3ZpMht2w"; let apikey2 = "dc03a9313amsh92a501f1f6bfeb3p1b9d0djsn1ff68b4277d9";
for (let i = 0; i < howmany; i++) { let url1 = "https://api.nytimes.com/svc/search/v2/articlesearch.json?q=" + q + "&fq=pub_year:("+ d +")&page=" + i + "&api-key=" + apikey; loadJSON(url1, gotData); } }
function gotData(data){
var articles = data.response.docs; for(var i = 0; i<articles.length;i++){ console.log("Article:", articles[i].headline.main, articles[i].web_url); articleObjs.push(new articleObj(articles[i].headline.main, articles[i].pub_date, articles[i].snippet, articles[i].web_url, articles[i].body));
}
}
function gotKeywords(words){ var keyWords = words; }
function setup() { createCanvas(windowWidth, windowHeight); }
class articleObj { constructor(h, d, s, url, b) { this.headline = h; this.date = d; this.snippet = s; this.url = url; this.body = b; } display(index){ const topOffset = 15; text(this.headline, 50, index * 40 + topOffset); text(this.date, 50, index * 40 + topOffset2); //text(this.date, 50, index * 40 + topOffset3); //createElement("h1", this.headline); //createElement("h2", this.date); } }
function draw() {
background(240); textFont('Georgia'); fill(0, 0, 100); for (let i = 0; i < articleObjs.length; i++) { articleObjs[i].display(i); }
}