Created
February 14, 2011 05:01
-
-
Save adeleinr/825504 to your computer and use it in GitHub Desktop.
Django Python Twitter
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
user = 'adeleinr' | |
messages_to_display = 5 | |
api = twitter.Api() | |
statuses = api.GetUserTimeline(screen_name=user, count=messages_to_display, include_entities=True) | |
messages = [] | |
for status in statuses: | |
# Replaces the @username mentions with a URL | |
replaced_mentions = re.sub(r'(@[^ $]+)', r'<a href="http://twitter.com/\1">\1</a>',status.text); | |
# Replaces the #tag's with a URL | |
replaced_hashtags = re.sub(r'(#[^ $]+)', r'<a href="http://twitter.com/#!/search?q=%23\1">\1</a>',replaced_mentions); | |
# Replaces the published times with a URL | |
replaced_times = (replaced_hashtags + " "+ | |
"<span class='tiny-font'><a href='http://twitter.com/#!/"+ | |
user+"/status/"+str(status.id)+"'>"+str(status.relative_created_at+ | |
"</a></span>")) | |
messages.append(replaced_times) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment