Twitter机器人回复

时间:2021-02-17 01:38:56

标签: python twitter tweepy

我正在尝试按照此处找到的教程 https://realpython.com/twitter-bot-python-tweepy/#how-to-make-a-twitter-bot-in-python-with-tweepy。我稍微编辑了它以尝试标记其回复的用户。它正在回复推文,但不标记原始用户。我不确定这是否是获取用户名并向用户发送推文的正确方法。

for tweet in tweepy.Cursor(api.mentions_timeline,
    since_id=since_id).items():
    new_since_id = max(tweet.id, new_since_id)
    sn = tweet.user.screen_name
    if tweet.in_reply_to_status_id is not None:
        continue
    if any(keyword in tweet.text.lower() for keyword in keywords):
        logger.info(f"Answering to {sn}")

        if not tweet.user.following:
            tweet.user.follow()
        m = "@%s new test reply" % (sn)
        api.update_status(
            m,
            in_reply_to_status_id=tweet.id
        )
return new_since_id

0 个答案:

没有答案