我正在制作一个推特机器人,它通过 Stream 收听特定 ID 的最新推文。当有来自特定用户的新推文时,然后按原样复制推文并将其发布到其他推特帐户上。
这是我的代码
import tweepy
import argparse
import time
BEARER_TOKEN = 'bearer token'
CONSUMER_KEY = 'CONSUMER_KEY D'
CONSUMER_SECRET = 'CONSUMER_SECRET'
ACCESS_TOKEN_KEY = 'ACCESS_TOKEN_KEY'
ACCESS_TOKEN_SECRET = 'ACCESS_TOKEN_SECRET'
PostBot = tweepy.Client(BEARER_TOKEN, CONSUMER_KEY, CONSUMER_SECRET,
ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET, wait_on_rate_limit=True)
class TweetStream(tweepy.StreamingClient):
new_tweet = {}
def on_connect(self):
print("Connected")
def on_includes(self, includes):
print("Inclueds: ", includes.media)
def on_tweet(self, tweet):
if tweet.referenced_tweets == None:
self.new_tweet['tweet'] = tweet.text
self.new_tweet["tweet"] = tweet.text
# print("New Tweet: ", tweet)
print("Get A Tweet Now Posting Wait...")
# if "media" in tweet.attachments:
# print("Got Media: ")
# PostBot.create_tweet(tweet)
stream = TweetStream(bearer_token=BEARER_TOKEN, wait_on_rate_limit=True)
def main():
# Delete previous rules as they exist indefinitely until deleted
previousRules = stream.get_rules().data
if previousRules:
stream.delete_rules(previousRules)
stream.add_rules(tweepy.StreamRule("from:elonmusk"))
stream.filter(
tweet_fields=["attachments", "text"],
expansions=["attachments.media_keys"],
media_fields=["url", "type"]
)
main()
我的问题是如何按原样复制推文并将其发布到另一个帐户
这就是我在 on_tweet 功能中得到的
新推文:一些文字 [图片网址]