def select_tweets(timeline, allow_rts=True, allow_replies=False, popular_only=True):
texts = []
for t in timeline:
if not 'retweeted_status' in t:
if not allow_replies and t['in_reply_to_status_id_str']:
continue
t['tweet_score'] = log(t['retweet_count'] + 1.0) + log(t['favorite_count'] + 1.0)
t['__is_rt__'] = False
texts.append(t)
else:
if allow_rts:
t['retweeted_status']['tweet_score'] = log10(t['retweet_count'] + 1.0) + log10(t['favorite_count'] + 1.0)
t['retweeted_status']['source_created_at'] = t['retweeted_status']['created_at']
t['retweeted_status']['created_at'] = t['created_at']
t['retweeted_status']['text'] = t['retweeted_status']['text']
t['retweeted_status']['__is_rt__'] = True
texts.append(t['retweeted_status'])
#texts = sorted(texts, key=lambda x: x['tweet_score'], reverse=True)[0:100]
if popular_only:
texts = list(filter(lambda x: x['tweet_score'] > 0, texts))
return texts
评论列表
文章目录