【发布时间】:2020-08-14 03:20:51
【问题描述】:
我正在尝试从我的时间线创建推文 ID 列表,然后提取有关每个推文 ID 的信息,例如用户名。我最终会尝试从我的时间线转发最“流行”的推文,我有逻辑可以在其他地方计算。
代码的第一部分有效,并从我的时间线上的推文中创建了一个推文 ID 列表,这些推文在 12 到 36 小时之间。我需要这样做,因为我计算最受欢迎推文的逻辑取决于点赞和转发的数量,所以如果我在过去 12 小时内这样做,则会偏向于较旧的推文。
def create_list(tweet_list):
for tweet in tweepy.Cursor(api.home_timeline).items():
tweet_date = tweet.created_at
tweet_age_seconds = tweet_date.timestamp()
tweet_age_hours = tweet_age_seconds / 3600
if (current_time_hours - tweet_age_hours) > 12 and (current_time_hours - tweet_age_hours) < 36:
tweet_list.append(tweet.id)
return tweet_list
然后我尝试遍历此推文 ID 列表以提取有关每个推文的信息,例如用户名。我正在尝试通过以下方式做到这一点,但不断收到'ResultSet' object has not attribute 'user.id' 错误。
for i in enumerate(tweet_list):
status = api.statuses_lookup(i)
print(str(status.user.id))
这会导致属性错误。如何选择从api.statuses_lookup() 调用中提取的状态?我最终会尝试为列表中的每条推文提取user.id,这样我就可以看到该用户有多少关注者。
【问题讨论】:
标签: python twitter tweepy attributeerror