def print_tweets(tweets): """ prints the tweets from tweets: list of tweet dicts """ print for tweet in tweets: text = get_tweet(tweet) text = text.encode('unicode-escape') text = ununicode(text) text = unescape(text) print parser(text) print
""" utilities """ import re import requests from requests_oauthlib import OAuth1 from HTMLParser import HTMLParser as parser parser = parser().unescape APP_KEY = 'LygFznM7If85hSM6bUxiVLi2t' APP_SECRET = 'INXtZ3OJ5IttsSJ9KrhwVPWdaL9SVvK4p2elD6nr5QiZfdwwVp' def strings_startswith(str_lst, char): """ returns a list of words that starts with char from all the strings str_lst : a list of strings """ words = [] pattern = r'[^\w](' + char + '\w+)' for string in str_lst: words.extend(re.findall(pattern, ' ' + string)) return words def ununicode(text): """ removes unicode combinations """ pat = r'http:\\u\d+' pat1 = r'\\u\d+' text = re.sub(pat, '', text) text = re.sub(pat1, '', text)
def unescape(inputStr): return parser().unescape(inputStr)