This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
multipub/lib/twitter/tweet_converter.py
2019-02-21 20:18:28 -06:00

41 lines
No EOL
1.4 KiB
Python

# TODO: Clean this up and write comments.
def convert_tweets(tweets):
recent_tweets = tweets
outtweets = []
for tweet in recent_tweets:
try:
outtweets.insert(0, {
'id':str(tweet.id_str),
'date':str(tweet.created_at),
'retweet':('RT @' in tweet.text),
'text':str(tweet.text.encode('utf-8'))[1:],
'hashtags':tweet.entities.get('hashtags'),
'mentions':tweet.entities.get('user_metions')
})
except:
try:
outtweets.insert(0, {
'id':str(tweet.id_str),
'date':str(tweet.created_at),
'retweet':('RT @' in tweet.full_text),
'text':str(tweet.full_text.encode('utf-8'))[1:],
'hashtags':tweet.entities.get('hashtags'),
'mentions':tweet.entities.get('user_metions')
})
except:
outtweets.insert(0, {
'id':str(tweet.id_str),
'date':str(tweet.created_at),
'retweet':True,
'text':str(tweet.retweeted_status.text.encode("utf-8"))[1:],
'hashtags':tweet.entities.get('hashtags'),
'mentions':tweet.entities.get('user_metions')
})
return outtweets