Tweeting from a django application

Download Template
A recent feature request for hatch was to have a twitter feed. A twitter feed would allow people to be notified when new config templates are created via twitter.

February 17, 2012

%{--- %{project_name}%/ ---}%
    'public': {
        'consumer_key':        '%{consumer_key}%',
        'consumer_secret':     '%{consumer_secret}%',
        'access_token_key':    '%{access_token_key}%,
        'access_token_secret': '%{access_token_secret}%'

%{--- %{project_name}%/%{application_name}%/ ---}%
from django.contrib.sites.models import Site

def send_tweet(title, url)
   import twitter
   from django.conf import settings
      api = twitter.Api(**account)
      tweet_message = "%s just added %s" %(title, url)
      status = api.PostUpdate(tweet_message)
      # I don't care if the tweet didn't go through.

def class Post(models.Model)
        def get_absolute_url(self):
	   #below generates the absolute url for this object
           return "http://%s/posts/%s" % (Site.objects.get_current().domain, self.slug)

	def save(self, *args, **kwargs):
	   super(Post, self).save()
	   send_tweet(, self.get_absolute_url())

You must be logged in to comment.