Skip to content

Instantly share code, notes, and snippets.

@adeleinr
Created February 14, 2011 05:01
Show Gist options
  • Save adeleinr/825504 to your computer and use it in GitHub Desktop.
Save adeleinr/825504 to your computer and use it in GitHub Desktop.
Django Python Twitter
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