User:452

Explain xkcd: It's 'cause you're dumb.
Revision as of 21:36, 1 April 2015 by 452 (talk | contribs) (how to get the reasons from 1506)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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);

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.