如果我串流,Tweepy不会打印出整个Tweet

时间:2019-04-25 11:43:30

标签: python twitter tweepy

我无法打印全部推文。问题是我已经包括了 tweet_mode=extended进入请求,但仍然无法显示整个tweet文本

from tweepy import OAuthHandler
import tweepy
import zugangsdaten
import sys

auth=OAuthHandler(zugangsdaten.consumer_key, 
zugangsdaten.consumer_secret)
auth.set_access_token(zugangsdaten.access_token, 
zugangsdaten.access_token_secret)
api = tweepy.API (auth)

class MyStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        non_bmp_map=dict.fromkeys(range(0x10000,sys.maxunicode+1),0xfffd)
    print(status.text.translate(non_bmp_map))      
def on_error(self, status_code):
    if status_code == 420:
        #returning False in on_data disconnects the stream
        return False

myStreamListener = MyStreamListener()
myStream=tweepy.Stream(auth=api.auth,listener=myStreamListener,tweet_mode="extended")
myStream.filter(track=['Donald Trump'])

改进的格式

当前输出:RT @twitter_user:乱七八糟的唐纳德又回来了。精神错乱的唐纳德(Donald)可以做这样的事情,因为它甚至不是新闻的重头戏,因为...

我希望显示整个推文,而不是仅显示140个字符。

1 个答案:

答案 0 :(得分:0)

这对我有用:

status = tweet if 'extended_tweet' in status._json: status_json = status._json['extended_tweet']['full_text'] elif 'retweeted_status' in status._json and 'extended_tweet' in status._json['retweeted_status']: status_json = status._json['retweeted_status']['extended_tweet']['full_text'] elif 'retweeted_status' in status._json: status_json = status._json['retweeted_status']['full_text'] else: status_json = status._json['full_text'] print(status_json)'