如何解决如何使用tweepy用json列表中的文本和图像回复推文
我希望每次提及该机器人时,该机器人以一定的文字和图片进行回复。例如文字是“小熊维尼”,图片是小熊维尼。我已经将图像和文本存储在json文件中。我得到的错误是这样的:
api.update_status("@"+tweet.user.screen_name+data[n]["text"]+media_ids=media_list,tweet.id)
^
SyntaxError: expression cannot contain assignment,perhaps you meant "=="?
我只是不知道如何写包含文本和图像的回复。同样,lastseen.txt文件是最后提到该机器人的推文的ID。
import tweepy
import time
import random
import json
consumer_key=''
consumer_secret=''
key=''
secret=''
auth=tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(key,secret)
api = tweepy.API(auth)
with open('pll/file.json') as json_file:
data = json.load(json_file)
randomlist = [0,1,2,3,4]
for i in range(0,4):
n = random.randint(0,4)
randomlist.append(n)
media_list = list()
response = api.media_upload(data[n]["image"])
media_list.append(response.media_id_string)
FILE_NAME = 'pll/lastseen.txt'
def read_last_seen(FILE_NAME):
file_read = open(FILE_NAME,'r')
last_seen_id = int(file_read.read().strip())
file_read.close()
return last_seen_id
def store_last_seen(FILE_NAME,last_seen_id):
file_write=open(FILE_NAME,'w')
file_write.write(str(last_seen_id))
file_write.close()
return
def reply():
tweets=api.mentions_timeline(read_last_seen(FILE_NAME),tweet_mode='extended')
for tweet in reversed(tweets):
print(str(tweet.id) + ' _ ' + tweet.full_text)
api.update_status("@"+tweet.user.screen_name+data[n]["text"]+media_ids=media_list,tweet.id)
store_last_seen(FILE_NAME,tweet.id)
reply()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。