我有一个脚本响应发送到句柄的推文。问题是它只在终端启动时运行一次,并停止工作。我已经安排它使用Python调度程序每分钟运行一次,但它不起作用。
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()
答案 0 :(得分:1)
调度程序的enter
方法在调度程序中设置单个,一次性事件,而不是重复事件。因此,即使您有意,也不会安排它每分钟运行一次。
我不认为sched
有任何计划重复事件的工具。所以你需要做的是使它调用的函数 - 在你的情况下,run_thejewels
- 重新安排事件的另一个实例。