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()