I am trying to have a Django script run every 5 minutes via cron on my dev laptop (Mac OS X). Here is the code in the script:
import sys
import os
def setup_environment():
pathname = os.path.dirname(sys.argv[0])
sys.path.append(os.path.abspath(pathname))
sys.path.append(os.path.normpath(os.path.join(os.path.abspath(pathname), '../')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
setup_environment()
from common.models import TweetCache
import datetime
def main():
print "(%s) Caching tweets..." % str(datetime.datetime.now())
previous_tweets = TweetCache.objects.filter(username='atmospherian')
for prev in previous_tweets:
prev.delete()
import twitter
api = twitter.Api()
tweets = api.GetUserTimeline('atmospherian')
for t in tweets:
tc = TweetCache(username='atmospherian', date=t.created_at, text=t.text)
tc.save()
if __name__ == '__main__':
main()
crontab:
*/5 * * * * python /absolute/path/to/tweet_cache.py
error from system mail:
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=jason>
X-Cron-Env: <USER=jason>
X-Cron-Env: <HOME=/Users/jason>
Date: Tue, 16 Feb 2010 17:45:00 -0500 (EST)
Traceback (most recent call last):
File "/Users/jason/Development/bandistry/tweet_cache.py", line 22, in <module>
from common.models import TweetCache
File "/Users/jason/Development/bandistry/common/models.py", line 1, in <module>
from django.db import models
ImportError: No module named django.db
can anyone tell me what im doing wrong?