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

44 lines
1.6 KiB
Python
Raw Permalink Normal View History

2019-02-16 01:17:41 -06:00
# 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'),
'reply':(tweet.in_reply_to_status_id_str)
2019-02-16 01:17:41 -06:00
})
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'),
'reply':(tweet.in_reply_to_status_id_str)
2019-02-16 01:17:41 -06:00
})
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'),
'reply':(tweet.in_reply_to_status_id_str)
2019-02-16 01:17:41 -06:00
})
return outtweets