首页 > 解决方案 > Python推文分析

问题描述

我在 Python 中有以下代码:

from datetime import date
from datetime import timedelta

def tweets_user_student(user):
  search_params = { 'screen_name': user,'result_type': 'recent', 'count': 1} 

  search_url = '{}1.1/statuses/user_timeline.json'.format(base_url)
  search_resp = requests.get(search_url, headers=search_headers, params=search_params)
  Data = json.loads( search_resp.content.decode("utf-8") )

  for tweet in Data:
    <GAP_1>
    if <GAP_2>:
        tweets_user_student = {tweet['user']['screen_name']: tweet['user']['followers_count']}
        dict_tweets_student.update(tweets_user_student)
        print(tweets_user_student)
    
list_users_student=[<GAP3>]
dict_tweets_student={}
for user in list_users_student:
  tweets_user_student(user)

print(dict_tweets_student)

我需要为每个用户显示分析上周推文的关注者数量。

我显示了上周发布的两个用户的推文数量。为此,我可以使用 datetime 模块以及 date 和 timedelta 对象,但我不知道该怎么做。有人可以帮助我吗?我该如何填补这些空白?

谢谢!

标签: pythontwitter

解决方案


推荐阅读