Tuesday, October 20, 2009

Because the hand that feeds tastes good

Indeed!
Even when it's your own... But that's another story...
and here's Nine Inch Nails!!

And now for something completely different...

Twitter has been good to me, more or less. By providing a new platform for my largely nonsensical rants, twitter has been feeding followers and readers into the maw of my endless ambition, and on my end I have been mildly abusive to it. Not really, but pretending in that vein, I have mildly abused the twitter api to draw out and play with the vaguely relevant json data from my twitter feed and that of others.

What do I mean? Nothing really, I actually was going to write something quite meaningful today, but..

Anywho, these are some example twitter api calls:

http://twitter.com/statuses/[followers|friends|user_timeline]/[screen-name].[format (ie, xml, atom, json, etc.)]

in addition you can throw in GET arguments like page=# and count=# or callback=function for the json format in particular.

Thus to call the third page of therandshow twitter feed in json with 20 results per page and send it to a callback called karl do thus:

http://twitter.com/statuses/user_timeline/therandshow.json?count=20&page=3&callback=karl
(note: you must have already declared a function named karl to callback to, else the Karl's won't come home no matter how hard you call)

Now you might say to yourself: "Hey this seems vaguely useful, but how can I waste that usefulness while helping to strain twitter's resources until it's inevitable implosion?"

Glad you asked Jim, not so glad you asked Sally.

Here's a sample use (and let me credit jquery for making this example within the reach of my immense laziness), and by sample I mean something I did to kill time and decided to half-justify by putting onto the web - behold twitter results displayed by day!

Dun-dun-dun!!!


<html>
<head>
<title>Abusing Twitter Every Day</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
function twitterCallback2(twits) {
twittier = [{date:0,tweets:[]}];
j=0;

for(i=0; i < twits.length;i++) {
settable = new Date();
settable.setTime(Date.parse(twits[i].created_at));
if(twittier[j].date==0) {
twittier[j].date = settable;
twittier[j].tweets.push(twits[i]);
dte =Date(twittier[j].date);
}
else if(twittier[j].date.getDay()!=settable.getDay()) {
j++;
twittier.push({date:settable,tweets:[twits[i]]});
}
else {
twittier[j].tweets.push(twits[i]);
}
}
str="";
for(i=0; i < twittier.length;i++) {
str += "<div><h2>"+twittier[i].date+"</h2>";
for(j=0; j < twittier[i].tweets.length;j++) {
for(k in twittier[i].tweets[j]) {
if(k!='user') {
str+= "<p>"+k+" : "+twittier[i].tweets[j][k]+"</p>";
}
else {
/* if you want for some reason to also display the your own user object */
str+= "<p>"+k+" : "+twittier[i].tweets[j][k].toSource()+"</p>";

}
}
// str+= "<pre>"+twittier[i].tweets[j].toSource().replace(/,/g,",\n")+"</pre>";
}
str+= "</div>";
}
$("#holder").append(str);
}
</script>
</head>
<body>
<div id="holder">
</div>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=1&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=2&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=3&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=4&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=5&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=6&callback=twitterCallback2"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/therandshow.json?count=100&page=7&callback=twitterCallback2"></script>
</body>
</html>



and so there it is. Rather random and vaguely cool, n'est pas? Just like my random evocation of my 3 years of middle school French.

So take it to your head, take it to your heart and remember Rand rocks. Goodnight Folks!

And God Bless.

1 comment:

Anonymous said...

[url=http://superonlinecasino24.com ]casino spellen [/url]thereof, when I shall bring again their captivity; The LORD of nations--were dragged again to unfamiliar light. The invaded amsterdams casino bonus