Sunday, 8 February 2015

Cron won't run Python Twitter Bot topic






It runs perfectly manually and in cron's bash environment - so I'm assuming there might be something about crontab in the OAuth process itself? I have tried running env in cron and pasting the PATH I found there also...

twitter_follow_bot.py

Code:


from twitter import Twitter, OAuth, TwitterHTTPError
import os


# put your tokens, keys, secrets, and Twitter handle in the following variables
OAUTH_TOKEN = "..."
OAUTH_SECRET = "..."
CONSUMER_KEY = "..."
CONSUMER_SECRET = "..."
TWITTER_HANDLE = "..."


# put the full path and file name of the file you want to store your "already followed"
# list in
# OMITTED - ALREADY_FOLLOWED_FILE = "already-followed.csv"


t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
            CONSUMER_KEY, CONSUMER_SECRET))




def search_tweets(q, count=100, result_type="recent"):
    """
        Returns a list of tweets matching a certain phrase (hashtag, word, etc.)
    """


    return t.search.tweets(q=q, result_type=result_type, count=count)


startuprun.py

Code:


from twitter_follow_bot import auto_fav


auto_fav("startup", count=100)


sudo crontab -e (the last line is an alternate tester - today is "7" in cron's calendar..

Code:


PATH=/usr/bin:/bin
SHELL=/usr/bin/bash


*/15 * * * * 1-2 /usr/bin/python /var/www/html/twitter/startuprun.py  >> /tmp/cron.output
*/15 * * * 3-4 /usr/bin/python /var/www/html/twitter/entrepreneurrun.py  >> /tmp/cron.output
*/15 * * * 5-6 /usr/bin/python /var/www/html/twitter/venturecapitalrun.py  >> /tmp/cron.output
*/1 * * * 7 /usr/bin/python /var/www/html/twitter/techrun.py >> /tmp/cron.output
*/1 * * * 7 python /var/www/html/twitter/techrun.py >> /tmp/cron.output


Errors are no longer writing to cron.output so I think it might be on twitters end.

Anyone know of any issues between cron and the authorisation process? Or maybe something else that I've missed? I've also tried putting a shebang for bash, python at the top of crontab but no joy...






No comments:

Post a Comment