rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Mar 20
2007

Twitter Timeline Javascript digg

This snippet draws a bar graph that tells you your twitter posting frequency per hour in the last 24 hours.

Screenshot

Twitter timeline javascript 0.2

Instructions

  1. Download Twitter Timeline Javascript v0.2 (Requires PlotKit and MochiKit).
  2. Edit TwitterTimeline.js and change the userid variable to your user-id. You’ll find your user-id at http://twitter.com/account/badge.
  3. You will need to include the javascript files:
    <script type="text/javascript" src="/js/MochiKit/MochiKit.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Base.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Layout.js"></script>
    <script type="text/javascript" src="/js/PlotKit/Canvas.js"></script>
    <script type="text/javascript" src="/js/PlotKit/SweetCanvas.js"></script>
    <script type="text/javascript" src="/js/TwitterTimeline.js"></script>
  4. Next, add the following lines where you want the Timeline to appear:
    <script type="text/javascript" src="/js/TwitterTimeline.js"></script>
    <div><canvas id="graph" height="200" width="400"></canvas></div>
    

For your reference, TwitterTimeline.js:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script type="text/javascript">
<!--
/*
 * Twitter Timeline Javascript v0.2 (March 20, 2007)
 * Pravin Paratey (http://www.dustyant.com)
 * Andrei Virlan  (http://its.squeak.in)
 *
 * Released under Creative Commons Attribution 2.5 Licence
 * http://creativecommons.org/licenses/by/2.5/
 *
 * Changelog:
 * 0.2 (Mar 20, 2007) - Moved to PlotKit to draw graphs
 * 0.1 (Feb 23, 2007) - Initial Release
 */
 
var userid = '754023'; // Change this value to your user-id
 
var timelineArray = new Array();
function drawGraph() {
    var layout = new PlotKit.Layout("bar", {});
    layout.addDataset("sqrt", timelineArray);
    layout.evaluate();
    var canvas = MochiKit.DOM.getElement("graph");
    var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, {});
    plotter.render();
}
 
function twitterCallback(obj) {
	// Create an array to hold the 24 hours of the day
	var hourArray = new Array(24);
 
	// Initialize array
	for(var i=0; i<24; i++) {
		hourArray[i] = 0;
	}
 
	for (var i=0; i<obj.length; i++) {
		// Get date
		var created_at = new Date(obj[i].created_at);
		if(obj[i].user.id == userid) {
			// Increment the hour
			hourArray[created_at.getHours()]++;
		}
	}
 
	// Construct the timeline
	for(var i=0; i<24; i++) {
		timelineArray[i] = new Array(i, hourArray[i]);
	}
	MochiKit.DOM.addLoadEvent(drawGraph);
}
// Makes the twitter call
document.write('<scr'+'ipt type="text/javascript"' +
	'src="http://twitter.com/statuses/friends_timeline/' +
	userid + '.json?callback=twitterCallback"></scr'+'ipt>');
-->
</script>

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Apr
07

Palindromic sub-sequences in python

This bit of python code returns all palindromic subsequences in the input string.

[Read More]
Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it!

[Read More]

Featured Projects

NLP classes for PHP

NLP classes for PHP

This is an ongoing project to develop a set of classes for Natural Language Processing. Some code would be ported from the NLTK project.

[Read More]

Deebot

Deebot

Deeb0t is an IRC chat bot capable of making meaningful conversation with other users. It also responds to commands issued by its owner.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.