Week 8 | Data | API | JSON
FOAAS[ F**k Off As A Service ]
https://www.foaas.com/
https://alpha.editor.p5js.org/projects/B1uk976Je
I want to start of by apologizing in advance because my assignment this week is a bit verbally aggressive. I was so damn mad I though I was going to explode. I was on a rampage…. and when I stumbled upon this FOAAS API, I decided to channel my rage into getting the API to work.
Trying to get the API to work and print as I wanted really help me forget what I was even mad about… because all of my energy had totally shifted to p5!
Although, not exactly as I wanted but its great!
Also, I had a bit of trouble with .child() and .parent(). According to your youtube tutorial video, they should have worked the same way but I found that .child() gave error in chrome when inspected. However, they both draw the same result.
// Input from user var button1; var button2; var input; var clearInput; var url = "https://www.foaas.com/"; var api1 = ["donut", "shakespeare", "linus", "king", "chainsaw", "outside", "madison", "nugget", "yoda", "bus", "xmas", "bday", "shutup", "bm", "gfy", "back", "think", "keep", "look", "thinking", "blackadder", "deraadt", "problem", "cocksplat"]; var api2 = ["this", "that", "everything", "everyone", "pink", "life", "thing", "thanks", "flying", "fascinating", "cool", "what", "because", "bye", "diabetes", "awesome", "tucker", "bucket", "family", "zayn", "mornin", "retard", "me", "single", "looking", "no", "give", "zero", "sake", "maybe", "horse", "too", "ridiculous", "bag", "rtfm"]; var myname = " with love, mint"; var printText; function setup() { noCanvas(); // Grab the input and button from HTML input = createInput(); input.id("input"); // input.position(100, 50); button1 = createButton('Go! Go! Go!'); button1.id("button1"); button1.mousePressed(search); // Clear page button2 = createButton('Clear'); button2.id("button2"); button2.mousePressed(clearDiv); var div = createDiv(""); div.id("print"); } // Clear function clearDiv(e) { console.log('clear') var parentDiv = document.getElementById("print"); parentDiv.innerHTML = ''; } // Run the API call function search() { console.log('im search') var chance = Math.random(0, 1); var randomVal1 = Math.floor(Math.random() * api1.length - 1); var randomVal2 = Math.floor(Math.random() * api2.length - 1);; var url1; var url2; var term = input.value(); if ( chance < 0.5) { console.log('im url1'); url1 = url + api1[randomVal1] + "/" + term + "/" + myname; // URL for querying the times loadJSON(url1, gotData, 'json'); // Query the URL, set a callback } else { console.log('im url2') url2 = url + api2[randomVal2] + "/" + myname; loadJSON(url2, gotData, 'json'); } } // Request is completed function gotData(data) { console.log(data); printText = createP(data.message + data.subtitle); var parentDiv = document.getElementById("print"); printText.parent(parentDiv); }