Thanks for the help,
Joe
--
----
Waylan Limberg
way...@gmail.com
DJANGO_SETTINGS_MODULE=python.module.path.to.project.settings.file
python yourjob.py
Here's what I use:
------
import sys, os
sys.path.append('/home/ohgoditb/django_projects')
sys.path.append('/home/ohgoditb/django_src/django/bin')
sys.path.append('/home/ohgoditb/django_src')
sys.path.append('/home/ohgoditb/python_libs/lib/python2.3/site-
packages')
sys.path.append('/home/ohgoditb/python_libs/bin/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'fallingbullets.settings'
from fallingbullets.apps.links import models
models.sync_magnolia_links()
from fallingbullets.apps.photos import models
models.sync_flickr_photos()
-------
Then just call "python that_file.py" from the cron job.
I think some of my paths in my $PATH are redundant and you'll notice
my fun little namespace collision with 'models', but it works well
enough for me. 'fallingbullets' is the name of the project.
Regards,
Tyson
%<------------------------------
#!/usr/bin/env python
import sys
sys.path.append('/path/to/django')
sys.path.append('/path/to/your/projects')
import os
# assuming /path/to/your/projects/myproject/settings.py
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from myproject.myapp.models import GreenStripedPotatoes
...
%<------------------------------
Alternatively you can add django and your projects folder to the
PYTHONPATH, and define DJANGO_SETTINGS_MODULE as an environment variable
before starting your script
e.g.:
$ export PYTHONPATH="$PYTHONPATH:/path/to/django:/path/to/your/projects"
$ export DJANGO_SETTINGS_MODULE="myproject.settings"
$ python /path/to/my/cronscript.py
The second method is more flexible as your sysadmin can write a shell
script that sets up the environment and then runs your script. Like this
your script can be used on different servers without changing it.
hope this helps
cheers
Steven
Also, if you're using Django's send_mass_mail, note that "As in
send_mail(), recipients in the same recipient_list will all see the
other addresses in the e-mail messages's 'To:' field." (from
http://www.djangoproject.com/documentation/email/#send-mass-mail)
I think if you want to use a "Bcc:" header, straight Python may be the
way to go. As the e-mail doc says, have a look at
http://www.python.org/doc/current/lib/module-smtplib.html (and
http://www.python.org/doc/current/lib/module-email.html).
Regards,
John