Login

automating twitter

Author:
lawgon
Posted:
July 1, 2009
Language:
Python
Version:
1.0
Score:
2 (after 2 ratings)

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
import twitter
from django.db.models.signals import post_save

def tweetit(sender,**kwargs):
    """
        extract relevant info and tweet it
        """
    if kwargs['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)

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 1 week ago
  5. Help text hyperlinks by sa2812 11 months ago

Comments

Please login first before commenting.