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.

  1.  
  2. import  twitter
  3. import  sys
  4.  
  5. if len(sys.argv) != 2:
  6.         print   "Provide a Twitter Username as Argument"
  7.         exit(-1)
  8.  
  9. api = twitter.Api()
  10. st = api.GetUserTimeline(sys.argv[1])
  11. sum = 0.0
  12. for s in st:
  13.         sum += (140.0len(s.text.encode("utf-8")))/140.0
  14.  
  15. print "%s internal fragmentation is %.2f%s" % (sys.argv[1], round(sum / len(st) * 100, 2), "%")
  16.  

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%

, , , , ,