rhiever / TwitterFollowBot

A Python bot that automates several actions on Twitter, such as following users and favoriting tweets.
GNU General Public License v3.0
1.3k stars 448 forks source link

crontab execution #135

Closed mablono5 closed 6 years ago

mablono5 commented 6 years ago

My issue is that i can wrap the .py in bash and run it from the command line using ./run.sh but when i have tried to create a cron job from this i recieve the error: Traceback (most recent call last): File "/home/pi/TwitterFollowBot/tweetbot.py", line 3, in my_bot = TwitterBot() File "/home/pi/TwitterFollowBot/TwitterFollowBot/init.py", line 42, in init self.bot_setup(config_file) File "/home/pi/TwitterFollowBot/TwitterFollowBot/init.py", line 78, in bot_setup with open(config_file, "r") as in_file: IOError: [Errno 2] No such file or directory: 'config.txt' bash script:

!/bin/bash

/usr/bin/python /home/pi/TwitterFollowBot/tweetbot.py

cronjob: /1 * python /home/pi/TwitterFollowBot/tweetbot.py >> /home/pi/python.log 2>&1

config.txt: OAUTH_TOKEN:example OAUTH_SECRET:example CONSUMER_KEY:example CONSUMER_SECRET:example TWITTER_HANDLE:example ALREADY_FOLLOWED_FILE:already-followed.txt FOLLOWERS_FILE:followers.txt FOLLOWS_FILE:following.txt USERS_KEEP_FOLLOWING: USERS_KEEP_UNMUTED: USERS_KEEP_MUTED: FOLLOW_BACKOFF_MIN_SECONDS:10 FOLLOW_BACKOFF_MAX_SECONDS:60

Running from the command line invokes the config file as expected and produces my required outcome. Running a cronjob does not. run.sh has been made an executable so has config.txt out of sheer desperation.

Does anyone have any idea why this issue would happen?

mablono5 commented 6 years ago

Solved the issue after head scratching.

Replace the config_file on line 78 with an absolute path, in my case the line now looks like:

with open("/home/pi/TwitterFollowBot/config.txt", "r") as in_file: