[python]我希望图像被标记为bot时通过tweepy在Twitter上以转推的方式发送]]

问题描述 投票:0回答:1

我想在机器人被标记的情况下通过Tweepy在Twitter上通过Tweepy以转发方式发送图像,但我碰到了墙,不知道为什么。它正在检测外部文件中的图像,但未使用它。我知道这有点含糊,但是关于Tweepy的文档让我很难理解,因为我昨天才刚接过Tweepy。任何帮助表示赞赏!

import tweepy
import time
import os



#keys

CONSUMER_KEY = 'xxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxx'
ACCESS_KEY = 'xxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxx'

#auth

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)



media = api.media_upload('cat_image.jpg')


#aquiring mentions
mentions = api.mentions_timeline()

#file import

FILE_NAME = 'last_seen_id.txt'

#operations

def retrieve_last_seen_id(file_name):
    f_read = open(file_name, 'r')
    last_seen_id = int(f_read.read().strip())
    f_read.close()
    return last_seen_id

def store_last_seen_id(last_seen_id, file_name):
    f_write = open(file_name, 'w')
    f_write.write(str(last_seen_id))
    f_write.close()
    return

def reply_to_tweets():
    print('replying to tweets...')
    #id fetching
    last_seen_id = retrieve_last_seen_id(FILE_NAME)
    mentions = api.mentions_timeline(
        last_seen_id,
        tweet_mode='extended')
    for mention in reversed(mentions):
        print(str(mention.id) + ' - ' + mention.full_text)
        last_seen_id = mention.id
        store_last_seen_id(last_seen_id, FILE_NAME)
        if 'cat' in mention.full_text.lower():
            print('found user @!')
            print('responding....')
            un = '@' + mention.user.screen_name
            #response tweet
            tweet = 'un'
            api.update_status(un, media, mention.id)





while True:
    reply_to_tweets()
    time.sleep(9)

我想在机器人被标记的情况下通过Tweepy在Twitter上通过Tweepy以转发方式发送图像,但我碰到了墙,不知道为什么。它正在检测外部文件中的图像,但未使用它。 ...

python twitter tweepy
1个回答
0
投票

我尚不清楚您看到的确切错误是什么,但是我认为您是在说读取了图像文件,并且发送了Tweet,但未附加媒体?

© www.soinside.com 2019 - 2024. All rights reserved.