我正在创建一个搜索谷歌搜索关键字的应用程序,并将搜索中的URL附加到列表中。然后将URL发布到twitter。
如何以每小时随机时间从列表中选取一个网址,然后在接下来的一个小时内随机选择下一个网址?
import tweepy, time
from google import search
CONSUMER_KEY = 'xxxx'
CONSUMER_SECRET = 'xxxx'
# Create a new Access Token
ACCESS_TOKEN = 'xxxx'
ACCESS_SECRET = 'xxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
#search google for url key links
lst = [] #list holding URL
for url in search('python', stop=20):
lst.append(url)
print(url)
lst = [ x for x in lst if "wiki" not in x ]
# What the bot will tweet
for line in lst:
api.update_status(line)
print line
print '...'
time.sleep(1)
print "All done!"
提前谢谢你。
答案 0 :(得分:0)
当每小时随机发布时,这行代码似乎有效:
for line in lst:
#api.update_status(line)
print line
print '...'
sleep(random.randint(1,60))