Created
February 21, 2013 22:27
-
-
Save lisawilliams/5008944 to your computer and use it in GitHub Desktop.
This is a Processing sketch which uses live data from the NYT Article Search API to create a "Texts from Hillary" meme. More about why (or whether) Bill got more mentions here: http://dataforradicals.com/texts-from-hillary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import blprnt.nytimes.*; | |
// Line above imports a Processing library that makes it easier to deal with the API | |
PImage bg; | |
int y; | |
//void setup() { | |
size(652, 360); | |
bg = loadImage("hillary.jpg"); | |
//} | |
//void draw() { | |
background(bg); | |
//} | |
// define the size of the window we'll be putting stuff in | |
//size(600, 200); | |
// background color of the window (white) | |
//background(255); | |
// Let's put in our NYT Article Search API key. TimesEngine.init is | |
// is a function in the blprnt.nytimes library that's already | |
// been written for us | |
TimesEngine.init(this, "GET AN NYT ARTICLE SEARCH API KEY"); | |
// Now we'll use the library's built in "Times Article Search" routine | |
TimesArticleSearch mySearch = new TimesArticleSearch(); | |
// Let's add some queries to our search | |
mySearch.addQueries("Hillary+Clinton"); | |
// Let's tell it what date range we want to search in. | |
// mySearch is a function from the blprnt.nytimes library, but | |
// "begin_date" and "end_date" are specific keys we can use with the NYT API. | |
mySearch.addExtra("begin_date", "20110101"); | |
mySearch.addExtra("end_date" , "20130115"); | |
// RESULTS PLZ!!! | |
TimesArticleSearchResult r = mySearch.doSearch(); | |
// Print the string "Results about Hillary Clinton," and then the | |
// total # of records that contain that name | |
println("Results about Hillary Clinton " + r.total); | |
mySearch.clearQueries(); | |
mySearch.addQueries("Bill+Clinton"); | |
TimesArticleSearchResult r2 = mySearch.doSearch(); | |
println("Results about Bill Clinton: " + r2.total); | |
// Hillary bar | |
fill(255); | |
rect(0,25,(r.total/5), 25); | |
text("NYT Mentions of Hillary Clinton " + r.total, 330, 40); | |
// Bill Clinton bar | |
fill(252,229,51); | |
rect(0,50,(r2.total/5),25); | |
text("NYT Mentions of Bill Clinton " + r2.total, 405, 65); | |
// Text from Hillary to make our meme complete | |
fill(255); | |
textSize(24); | |
text("BILL, STOP BEING SUCH AN ATTENTION HOG.", 50, 325); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment