0

I have a script which responds to tweets sent to a handle. The problem is it only runs once, upon initiation in the Terminal, and ceases to work. I've scheduled it to run every minute using the Python scheduler but it isn't working.

import sched, time, tweepy
#from our keys module (keys.py), import the keys dictionary
from keys import keys

s = sched.scheduler(time.time, time.sleep)

def run_thejewels(sc):

    CONSUMER_KEY = keys['consumer_key']
    CONSUMER_SECRET = keys['consumer_secret']
    ACCESS_TOKEN = keys['access_token']
    ACCESS_TOKEN_SECRET = keys['access_token_secret']

    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth)

    twt = api.search(q='@twitterhandle')

    #list of specific strings we want to check for in Tweets
    t = ['TLOP',
         'FS4',
         'ULB']

    u = ['HL',
         'FSMH',
         'FADE']

    for s in twt:
        for i in t:
            if i in s.text:
                sn = s.user.screen_name
                m = "@%s Hello bruv" % (sn)
                s = api.update_status(m, s.id)

    for p in twt:
        for j in u:
            if j in p.text:
                pn = p.user.screen_name
                m = "@%s Hello bro" % (pn)
                p = api.update_status(m, p.id)

s.enter(60, 1, run_thejewels, (s,))
s.run()

1 Answer 1

1

The scheduler's enter method sets up a single, one-time event in the scheduler, not a repeating event. So you haven't "scheduled it to run every minute", even if you intended to.

I don't think sched has any facility for scheduling repeating events. So what you will need to do is to make the function it calls -- in your case, run_thejewels -- reschedule another instance of the event.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.