automating twitter

Assume you have a model called Delegate and you want to tweet whenever a new Delegate registers, the code above will do this. You need to install python-twitter.

1
2
3
4
5
6
7
8
9
10
11
12

importtwitterfromdjango.db.models.signalsimportpost_savedeftweetit(sender,**kwargs):""" extract relevant info and tweet it """ifkwargs['created']:t=twitter.Api(settings.TWITTER_USER,settings.TWITTER_PASSWORD)t.PostUpdate("%s has registered as a delegate"%(kwargs['instance']))post_save.connect(tweetit,sender=Delegate)