我差不多完成了这个机器人我只需要帮助自动化它的输出来通过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()
答案 0 :(得分:0)
我不是很清楚你的问题,我只是看到这个api能够发送消息,你只需要通过这个api随机获取消息就可以转到指定的用户
API.send_direct_message(user / screen_name / user_id,text)
从身份验证用户向指定用户发送新的直接消息。
参数:
1: user – The ID or screen name of the recipient user.
2: screen_name – screen name of the recipient user
3: user_id – user id of the recipient user
返回类型:DirectMessage对象