I am using python-twitter on my site. I have a problem when the
Twitter site is down. This results in an error message. I did not
found out if the users gets an error message or not. To use Twitter on
my site I have this context_processors.py

import datetime
import time
from django.conf import settings
from django.core.cache import cache
import twitter

def latest_tweet( request ):
        tweet = cache.get( 'tweet' )

        if tweet:
                return {"tweet": tweet}

        tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
count=5 )
        for s in tweet:
                s.date =
datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S
+0000 %Y" )[0:6]))
        cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )

        return {"tweet": tweet}

My idea is to put the cache.set( 'tweet', tweet,
settings.TWITTER_TIMEOUT ) in a view, and call this view in a cron
job. Is this the right way to solve this?

The context_processors.py is heavily based on the example i found in
this site btw:
http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-site/

Rob

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to