使用Tweepy将扩展推文保存到CSV吗?

问题描述 投票:1回答:1

我正在尝试使用Tweepy将扩展的tweet保存到CSV文件,但是这些tweets仅持续显示直到140个字符的限制。我将截断的参数设置为False,并将tweet_mode设置为“ extended”,但是仍然无法获取完整的tweet来显示在CSV文件中。有什么想法吗?

#!/usr/bin/python
import tweepy
import csv #Import csv
auth = tweepy.auth.OAuthHandler('XXX', 'XXX')
auth.set_access_token('XXX', 'XXX')

api = tweepy.API(auth)

# Open/create a file to append data to
csvFile = open('file.csv', 'a')

#Use csv writer
csvWriter = csv.writer(csvFile)

for tweet in tweepy.Cursor(api.search,
                           q = "query",
                           truncated = False,
                           tweet_mode= "extended",
                           since = "2019-12-11",
                           until = "2019-12-18",
                           wait_on_rate_limit = True,
                           lang = "en").items():
    if (not tweet.retweeted) and ('RT @' not in tweet.full_text):  
        csvWriter.writerow([tweet.created_at, tweet.full_text.encode('utf-8')])
        print(tweet.created_at, tweet.full_text)
csvFile.close()
python csv twitter tweepy
1个回答
0
投票

Passing parameters into the API method section of the Cursor Tutorial中所述,馈给tweepy.Cursor()的关键字参数将在调用时传递给api.search

但是,api.search方法不使用tweet_mode关键字参数-请参见tweepy文档中的API.search。实际上,唯一使用它的API端点似乎是API.search(请参阅api.lookup_users())。

换句话说,似乎api.lookup_users()关键字参数只是被source code方法忽略了。如果您查看tweet_mode="extended",则在最终的API调用中不会使用它。

两个建议:

  1. 如果未实际实现api.search关键字参数,则可能需要在source code中提交错误报告。

  2. 或者,尝试将代码分为两个步骤:第一步,使用tweet_mode获取与您的搜索相匹配的推特ID的列表。然后,使用生成的tweet ID列表,并根据tweepy repo on Github调用api.search。如果他们的示例不起作用,那是从tweepy存储库中的错误报告开始的好地方!

© www.soinside.com 2019 - 2024. All rights reserved.