- #instalar python – twitter http://code.google.com/p/python-twitter/downloads/list
- import twitter
- import re
- api = twitter.Api(username, password)
- #1. actualizar el estado
- api.PostUpdate(‘Tweet desde python ;)’) #
- #2. recuperar tus posts con links a otros uasuarios o los hashtags
- statuses = api.GetUserTimeline()
- posts=[]
- for s in statuses:
- tweet = s.text;
- hash_regex = re.compile(r‘#[0-9a-zA-Z+_]*’,re.IGNORECASE)
- user_regex = re.compile(r‘@[0-9a-zA-Z+_]*’,re.IGNORECASE)
- savelog(hash_regex,‘hashR’)
- savelog(smart_str(tweet),‘tweet’)
- for tt in user_regex.finditer(tweet):
- url_tweet = tt.group(0).replace(‘@’,”)
- tweet = tweet.replace(tt.group(0),
- ‘<a href=”http://twitter.com/’+
- url_tweet+‘” title=”‘+
- tt.group(0)+‘”>’+
- tt.group(0)+‘</a>’)
- for th in hash_regex.finditer(tweet):
- url_hash = th.group(0).replace(‘#’,‘%23’)
- if len ( th.group(0) ) > 2:
- tweet = tweet.replace(th.group(0),
- ‘<a href=”http://search.twitter.com/search?q=’+
- url_hash+‘” title=”‘+
- th.group(0)+‘”>’+
- th.group(0)+‘</a>’);
- posts.append({‘summary’: tweet})