【发布时间】:2017-08-18 21:19:44
【问题描述】:
我几乎完成了这个机器人我只需要帮助自动化它的输出以通过 tweepy api。我有 3 个函数,前 2 个是列表中的随机句子,第三个将在两者之间随机交替。我的问题是将第三个函数的输出打印到我的 twitter 机器人上,我假设您使用 api.update_status() 和 sleep 来自动化它,但即使在阅读完文档后我也不确定如何将它们与我的功能。
# -*- coding: utf-8 -*-
import random
import tweepy
from time import sleep
from credentials import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
def sentence_type():
words = [["sentence1","sentence2","sentence3"],
["conjunction1","conjunction2","conjunction3"],
["sentence1, sentence2, sentence3],
["sentence1, sentence2, sentence3"]]
print( ' '.join([random.choice(w) for w in words]))
def sentence_type_2():
words = [["sentence1","sentence2","sentence3"],
["conjunction1","conjunction2","conjunction3"],
["sentence1, sentence2, sentence3],
["sentence1, sentence2, sentence3"]]
print( ' '.join([random.choice(w) for w in words]))
def get_Sentence():
num = random.randrange(1, 3)
if num == 1:
sentence_type()
elif num == 2:
sentence_type_2()
get_Sentence()
【问题讨论】:
标签: python python-3.x twitter bots tweepy