如何在转推中获取完整的推文文本(不使用 tweepy!)?

How to get full tweet text in retweets (not using tweepy!)?

我有几个包含 Twitter 数据的 ndjson 文件。我 运行 遇到了问题,对于转推,词典的“文本” 属性 仅包含前 140 个字符。我想提取完整的推文。

通过其中一条推文和 运行 以下代码:

data.get('includes')['tweets']

我得到以下结果。

[{'attachments': {'media_keys': [‘’1234”]},
  'author_id': “1234”,
  'conversation_id': “1234”,
  'created_at': '2021-02-10T14:27:19.000Z',
  'entities': {'annotations': [{'end': 111,
     'normalized_text': 'Scotland',
     'probability': 0.9519,
     'start': 104,
     'type': 'Place'}],
   'hashtags': [{'end': 50, 'start': 35, 'tag': 'ChineseNewYear'}],
   'urls': [{'display_url': 'pic.twitter.com/1234’,
     'end': 221,
     'expanded_url': ‘urlwuhuu,
     'start': 198,
     'url': “another one”}]},
  'id': “1234”,
  'lang': 'en',
  'possibly_sensitive': False,
  'public_metrics': {'like_count': 7,
   'quote_count': 0,
   'reply_count': 6,
   'retweet_count': 3},
  'reply_settings': 'everyone',
  'source': 'Twitter Web App',
  'text': “FULL TWEET THAT I WANT TO GET”}]

问题是我现在拥有的是列表而不是字典。要获取推文(在列表末尾),我不能使用 .get 函数或使用字符串的索引。

解决此问题的最佳方法是什么?

使用list comprehension怎么样,例如:

tweets_list = data.get('includes')['tweets']
tweet_texts  = [ tweet['text'] for tweet in tweets_list ] # gets the texts of all tweets, as a list
text = tweet_texts[0] # get “FULL TWEET THAT I WANT TO GET” from your example