Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

python - Tweepy Truncated Status

I was mining user timeline data with tweepy and, have faced some difficulties in understanding the following:

  1. Is the 'retweeted' and 'truncated' attribute referring to the same thing (i.e., status text beyond 140 characters)?
  2. If not, what is the difference?
  3. I came across a stackoverflow question where someone asked how to retrieve status text which has been 'chopped' due the the length being over 140 characters. It suggested that there is a retweeted attribute in the _json dictionary which will be true if that is the case and the full status text will under status->retweeted_status->text. However, I have not been able to find it and, the only status text was under status->text ending with '...'. Did I get this wrong and if so, how do I get the full text?

Thanks for your help in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Is the 'retweeted' and 'truncated' attribute referring to the same thing (i.e., status text beyond 140 characters)? If not, what is the difference?

No, tweets can be truncated not only after a retweet (forward), but also after a reply or a mention (see my example below which is not a retweet). If it is the case, 'truncated' will be set to 'True' (and 'retweeted' will be True or False). It is also possible to have 'retweeted' equals to True while 'truncated' being equals to False, if the tweet is not truncated because its size is well below 140 characters.

It suggested that there is a retweeted attribute in the _json dictionary which will be true if that is the case and the full status text will be under status->retweeted_status->text.

This is true only if the tweet is a genuine retweet. Actually the retweeted_status could itself be truncated if it is coming from another truncated tweet. The best way is to use the tweet_mode='extended' parameter in Tweepy to retrieve the full text (unfortunately not documented in the Tweepy doc). For instance:

(not extended)

print api.get_status('862328512405004288')._json['text']

@tousuncotefoot @equipedefrance @CreditAgricole @AntoGriezmann @KMbappe @layvinkurzawa @UmtitiSam J'ai jamais vue d… https://tco/kALZ2ki9Vc

(extended)

print api.get_status('862328512405004288', tweet_mode='extended')._json['full_text']

@tousuncotefoot @equipedefrance @CreditAgricole @AntoGriezmann @KMbappe @layvinkurzawa @UmtitiSam J'ai jamais vue de match de foot et cela ferait un beau cadeau pour mon copain !! ????????????????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...