Forums

Converting script to scheduled task

In my Django app, I have a script (called players_scrape.py) that is running fine both on the web and as well as in a Bash console. Command that I used there is (assuming I am located in the right directory):

python manage.py runscript players_scrape

However when I try to put it in a schedule task with the following command:

/home/texouze/.local/bin/python /home/texouze/django_projects/mysite/manage.py runscript players_scrape.py

it throws the following error:

CommandError: An error has occurred running scripts. See errors above. When you want to use social login, please see dj4e-samples/github_settings-dist.py Using registration/login.html as the login template No (valid) module for script 'players_scrape.py' found Try running with a higher verbosity level like: -v2 or -v3

I am a bit at a loss, there seems to be many topics referencing scripts and scheduled tasks but none seem to cover my issue, although I am very very new at this...

Try "players_scrape" instead of "players_scrape.py"

It does run indeed now, I feel very dumb... However now my script fails because it references files and folders/directories in it. Again, the script runs well in a Bash console but as a scheduled task, I get the following error:

FileNotFoundError: [Errno 2] No such file or directory:

Does it mean I have to rewrite the whole script differently (and updating all the paths in it) for it to run as a scheduled task?

You could debug it with docs from https://django-extensions.readthedocs.io/en/latest/runscript.html

This now works indeed (by adding --chdir and the explicit directory path), thank you very much for the assistance here!

Great -- glad we could help!