1
我需要此程序在15分鐘後重新啓動,並重新執行其過程。我需要它在一個計時器上,所以它的示例動態啓動15分鐘,沒有任何用戶輸入,它只會重置並重新啓動並在Python shell中重新啓動。需要程序在一定的時間後繼續重新啓動
from twython import Twython, TwythonError
import time
import random
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
start_time = time.time()
search_results = twitter.search(q="lol", count=100)
try:
for tweet in search_results["statuses"]:
try:
st= tweet["entities"]["user_mentions"]
if st != []:
screen_name = st[0]["screen_name"]
twitter.create_friendship(screen_name = st[0]["screen_name"])
twitter.retweet(id = tweet["id_str"])
for name in bot_detectors:
if name == screen_name:
try:
twitter.destroy_friendship(screen_name = st[0]["screen_name"])
twitter.destroy_status(id = tweet["id_str"])
twitter.create_block(screen_name=name)
except TwythonError as e:
print (e)
你爲什麼不考慮類似'cron'或'Windows Scheduler'?那些更靈活,你可以專注於業務邏輯? –
有關cron的更多詳細信息,您絕對應該使用而不是依賴python計時器。 http://stackoverflow.com/questions/15033542/crontab-formatting-every-15-minutes –