我想制造一个机器人,当它从一个特定的帐户检测到一个新的tweet时(在我的代码中是这样的: NASA),它在我的键盘上做一个动作(用键盘导入)。问题是我不知道如何将两者联系起来。我确信我将不得不使用"if“,但是twitter python版本(tweepy)的API很难理解。
import keyboard
import tweepy
import auth
#Use the twitter Api to read if there is a new tweet
api.user_timeline(screen_name="NASA")
#action of my keyboard that performs the action of pressing f11
keyboard.send("F11")
print("New tweet, F11 was pressed.")```发布于 2022-01-14 20:33:54
正如API所说的这里,该方法返回最新tweet的集合。您可以尝试运行以下内容:
import keyboard
import tweepy
import auth
collection_of_tweets = api.user_timeline(screen_name="NASA")
print("Whatever_the_string")在代码编辑器中的打印行上放置一个断点,然后悬停在collection_of_tweets上。它应该向您显示该名称的值。然后,可以将最后一条tweet存储在另一个名称中,并每隔X秒、每几天运行一次脚本,或者检查存储的最后一条tweet是否相等(可能比较两个tweet的时间戳,而不是整个对象的时间戳)与从方法接收的最后一个tweet。
https://stackoverflow.com/questions/70715998
复制相似问题