Twitter Internal Fragmentation: Python + Twitter

As a toy project to play a little bit more with Python and accessing Twitter, I came out with the idea of calculating the Internal Fragmentation of user’s tweet.

To interface with Twitter services I used the Twitter extension located at http://code.google.com/p/python-twitter/, which has a pretty straightforward API.

The script shown below gives you back what average percentage of your last 20 tweets have been wasted.

import  twitter
import  sys
 
if len(sys.argv) != 2:
        print   "Provide a Twitter Username as Argument"
        exit(-1)
 
api = twitter.Api()
st = api.GetUserTimeline(sys.argv[1])
sum = 0.0
for s in st:
        sum += (140.0 - len(s.text.encode("utf-8")))/140.0
 
print "%s internal fragmentation is %.2f%s" % (sys.argv[1], round(sum / len(st) * 100, 2), "%")

And now some results:

$ python twinternal.py GabrielGonzalez
GabrielGonzalez internal fragmentation is 39.89%
$ python twinternal.py 48bits
48bits internal fragmentation is 36.79%
$ python twinternal.py reversemode
reversemode internal fragmentation is 38.72%
$ python twinternal.py aramosf
aramosf internal fragmentation is 32.41%

One thought on “Twitter Internal Fragmentation: Python + Twitter

Comments are closed.