44 lines
No EOL
1.6 KiB
Python
44 lines
No EOL
1.6 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'),
|
|
'reply':(tweet.in_reply_to_status_id_str)
|
|
})
|
|
|
|
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)
|
|
})
|
|
|
|
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)
|
|
})
|
|
|
|
return outtweets |