2017-03-26 2 views
0

나는이 봇으로 거의 끝났습니다. tweepy API를 통해 출력을 자동화하는 데 도움이 필요합니다. 나는 3 개의 함수를 가지고 있는데, 목록에서 처음 2 개의 임의 문장을 얻었고, 3 번째 함수는 2 개를 무작위로 번갈아 나타낼 것이다. 내 문제는 내 트위터 봇에 세 번째 기능의 출력물을 인쇄하는 것입니다. 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

, 나는 그냥 그냥 무작위로 갈 수있는이 API를 통해 메시지를 다시받을 필요가,이 API는 메시지를 보낼 수 있습니다 참조 지정된 사용자

API.send_direct_message (사용자/SCREEN_NAME/USER_ID 텍스트)

는 인증 사용자로부터 특정 사용자에게 새로운 메시지를 직접 전송.

매개 변수 :

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 객체

+0

그래서 난 그냥 이것으로 내 정보를 연결 것이고, 내 코드에 어딘가에 붙여? 내 주요 문제는 내 함수 출력으로 봇의 상태를 업데이트 할 수 없다는 것입니다.이 형식을 사용하면 출력을 자동화 할 수 있습니까? – spitnik11