Tuesday, October 2, 2012

Re: Running Shell script to run Django shell and then scp files to server...

On 10/02/2012 04:47 PM, Tom Evans wrote:
> On Tue, Oct 2, 2012 at 3:09 PM, Chris McComas <mccomas.chris@gmail.com> wrote:
>> I have a script in Django that I run manually 'python manage.py shell' and
>> then 'from sports import scores' and it goes out and pulls scores from a
>> couple URLs, modifies the data, and saves it to a SQLite database. Once that
>> process runs I manually scp my files to a server...
>>
>> What I'd like to do is write a shell script that I can run on a cron to run
>> the process at set periods, both actions.
>>
>> How would I do this so it properly runs the Django shell script?
>>
>
> You can write your own custom command - so run "python manage.py mycommand":
>
> https://docs.djangoproject.com/en/1.4/howto/custom-management-commands/
>
> Or you can setup your environment correctly, eg PYTHONPATH,
> DJANGO_SETTINGS_MODULE et al, and run a regular python script. No docs
> for this one, and I've always done the former rather than the latter.

If you don't want to write a management command:

This is what you roughly have to do:

import os, import sys
# setup sys.path such, that it finds all required modules

# New setup the environment so, that django settings can be found
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_project.settings'

# next lines recommended to be sure your own code can use logging
from django.conf import settings

# DO NOT REMOVE NEXT COMMAND (It forces django.setting's
# lazy evaluation to evaluate)
LOGGING = settings.LOGGING

import logging
# Now you can use logging with django setting's log setup

# Now You're free to use django

from your_project.your_app.models import MyModel












>
>
> Cheers
>
> Tom
>


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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate