# 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