Difference between revisions of "User:452"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(how to get the reasons from 1506)
 
Line 29: Line 29:
 
next();
 
next();
 
setInterval('next()', 10000);</nowiki>
 
setInterval('next()', 10000);</nowiki>
 
+
(Go to xkcd, and paste it in the browser console.)
 
I've determined 10 seconds to be the time you keep getting the same data, so there's no reason to poll the server more frequently than that.
 
I've determined 10 seconds to be the time you keep getting the same data, so there's no reason to poll the server more frequently than that.
  

Revision as of 21:36, 1 April 2015

http://c0.xkcd.com/xb/feed

Structure

feed: Array[3] {
Objectid: "a88f9898-8ae9-5b33-93e6-a5993daa922c"
img: "022f762b-9483-519c-8e6e-bd7a0ed5e2ba"
kind: "post"
poster: "Frances51"
profpic: "user-14.png"
text: "Never will follow the instructions on google maps again."
}
prompt {
captions: Array[5]
id: "21bd52d8-a3a4-590f-8888-db854fb52ce3"
img_id: "21bd52d8-a3a4-590f-8888-db854fb52ce3"
poster: "Bool Hand Luke"
profpic: "user-4.png"
reason: "RDBMS completely forgot how inner joins work"
}

Script to get reasons:

reasons = new Array();
function next() {
  $.getJSON('http://c0.xkcd.com/xb/feed').done(function (data) {
        console.log(data.prompt.reason);
        if (reasons.indexOf(data.prompt.reason) == -1) reasons.push(data.prompt.reason);
  });
}
next();
setInterval('next()', 10000);

(Go to xkcd, and paste it in the browser console.) I've determined 10 seconds to be the time you keep getting the same data, so there's no reason to poll the server more frequently than that.

You can check on the reason variable at any time.

I'm only interested getting in the reasons, feel free to adapt this script to get whatever else.