banool/recreation-gov-campsite-checker

Trouble implementing in cron

Opened this issue · 1 comments

Hi there, I'm able to get the script to run perfectly when launched from the terminal window, but run into issues when I try to command it through cron. Could anyone post the syntax their using for their cronjob? Mine is below. seems to be able to check the sites fine but has trouble handing off to the notifier.

(sorry if its obvious, I'm new and grateful for any pointers)

cronjob:

          • cd /home/pi/Documents/Python/recreation-gov-campsite-checker && /home/pi/Documents/Python/recreation-gov-campsite-checker/myvenv/bin/python /home/pi/Documents/Python/recreation-gov-campsite-checker/camping.py --start-date 2021-04-22 --end-date 2021-04-24 --nights 1 --stdin < parks.txt | python notifier.py @xxx >> ~/cron.log 2>&1

cron.log output:
Traceback (most recent call last):
File "notifier.py", line 8, in
from camping import SUCCESS_EMOJI
File "/home/pi/Documents/Python/recreation-gov-campsite-checker/camping.py", line 10, in
from dateutil import rrule
ImportError: No module named dateutil

cron runs jobs with a minimal path that does not include the python modules. This may be solved by any method to set the PATH to the correct value. I created a shell script that, among other things, sets the PATH first and then runs the python.