是否可以使用 Tweepy 模块来获取添加关注者的日期?
Is it possible to use the Tweepy module to get the date followers were added?
如果我不知道如何搜索 Tweepy 文档,请提前致歉。总的来说,我对 python/programming 很陌生。
我编写了一个小脚本来为我管理的工作帐户提取 Twitter 关注者数据。我想调查 何时 关注者添加了我们,看看我们的帖子是否增加了参与度。我想不通的是我是否可以使用 Tweepy 模块来提取此特定信息(当关注者添加我们时)?
提前感谢您的帮助。我的 MWE:
import tweepy
import pandas as pd
# Load API keys
consumer_key = "my_consumer_key"
consumer_secret = "my_consumer_secret"
access_token = "my_access_token"
access_token_secret = "my_access_token_secret"
# Authenticate access to Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Get the list of followers for the account
followers = api.followers_ids()
# Create a user map
userMap = {}
# Loop over all users
for f in followers:
# create a temporary list
tempList = []
try:
tweets = api.user_timeline(f, count = 33) # pull the 33 most recent tweets
except tweepy.TweepError:
print('Failed to run command.') # Tweepy throws an error if a user hasn't tweeted
# Loop over all tweets per each user f
for t in tweets:
tempList.append(t)
userMap[f] = tempList
# Create lists of pertinent data
dateList = []
favList = []
rtList = []
keyList = []
def genList(tweetList):
for tweets in tweetList:
for t in tweets:
keyList.append(str(t.id))
dateList.append(str(t.created_at))
favList.append(str(t.favorite_count))
rtList.append(str(t.retweet_count))
genList(userMap.values())
# Create a pandas data frame
df = pd.DataFrame(list(zip(keyList, dateList, favList, rtList)),
columns = ['userID', 'created_at', 'favorited', 'retweeted'])
Twitter 未提供此信息。
followers/list
(在 Tweepy followers()
方法中)returns User 对象的列表。看来唯一的解决办法就是自己监控变化和管理历史。
如果我不知道如何搜索 Tweepy 文档,请提前致歉。总的来说,我对 python/programming 很陌生。
我编写了一个小脚本来为我管理的工作帐户提取 Twitter 关注者数据。我想调查 何时 关注者添加了我们,看看我们的帖子是否增加了参与度。我想不通的是我是否可以使用 Tweepy 模块来提取此特定信息(当关注者添加我们时)?
提前感谢您的帮助。我的 MWE:
import tweepy
import pandas as pd
# Load API keys
consumer_key = "my_consumer_key"
consumer_secret = "my_consumer_secret"
access_token = "my_access_token"
access_token_secret = "my_access_token_secret"
# Authenticate access to Twitter API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# Get the list of followers for the account
followers = api.followers_ids()
# Create a user map
userMap = {}
# Loop over all users
for f in followers:
# create a temporary list
tempList = []
try:
tweets = api.user_timeline(f, count = 33) # pull the 33 most recent tweets
except tweepy.TweepError:
print('Failed to run command.') # Tweepy throws an error if a user hasn't tweeted
# Loop over all tweets per each user f
for t in tweets:
tempList.append(t)
userMap[f] = tempList
# Create lists of pertinent data
dateList = []
favList = []
rtList = []
keyList = []
def genList(tweetList):
for tweets in tweetList:
for t in tweets:
keyList.append(str(t.id))
dateList.append(str(t.created_at))
favList.append(str(t.favorite_count))
rtList.append(str(t.retweet_count))
genList(userMap.values())
# Create a pandas data frame
df = pd.DataFrame(list(zip(keyList, dateList, favList, rtList)),
columns = ['userID', 'created_at', 'favorited', 'retweeted'])
Twitter 未提供此信息。
followers/list
(在 Tweepy followers()
方法中)returns User 对象的列表。看来唯一的解决办法就是自己监控变化和管理历史。