Created
February 2, 2010 04:04
-
-
Save luispedro/292344 to your computer and use it in GitHub Desktop.
get twitter status
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
#!/usr/bin/env python | |
# Copyright 2010 (C) Luis Pedro Coelho | |
# License: MIT | |
import urllib2 | |
import simplejson | |
header = '''\ | |
Luis Pedro Coelho | |
http://luispedro.org | |
''' | |
username = 'luispedrocoelho' | |
microsummary = urllib2.urlopen('http://www.twitter.com/statuses/user_timeline/%s.json?count=1' % username).read() | |
status = simplejson.loads(microsummary) | |
status = status[0]['text'] | |
def wrap(status): | |
if len(status) < 72: return status | |
words = status.split() | |
lines = [] | |
line = [] | |
while words: | |
next_word = words.pop(0) | |
if line and sum(map(len,line)) + len(line) + len(next_word) > 72: | |
lines.append(" ".join(line)) | |
line = [' '] | |
line.append(next_word) | |
lines.append(" ".join(line)) | |
return "\n".join(lines) | |
status = wrap(status) | |
print header | |
print status | |
print '(http://twitter.com/%s)' % username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment