public_talks/2016_02_26_columbia/get_tweets.py
def parse_twitter_response(twitter_response, min_rts=500, strip_non_ascii=True):
    """Extract requested variables from Twitter API response. Yield each tweet
    one at a time with a generator. Available keys:

    [u'contributors', u'truncated', u'text', u'is_quote_status',
    u'in_reply_to_status_id', u'id', u'favorite_count', u'source',
    u'retweeted', u'coordinates', u'entities', u'in_reply_to_screen_name',
    u'in_reply_to_user_id', u'retweet_count', u'id_str', u'favorited',
    u'retweeted_status', u'user', u'geo', u'in_reply_to_user_id_str',
    u'possibly_sensitive', u'lang', u'created_at',
    u'in_reply_to_status_id_str', u'place', u'metadata']
    """
    for result in twitter_response['statuses']:
        tweet_datetime = result['created_at']

        text = result['text'].encode('utf_8')
        if strip_non_ascii:
            text = ''.join([i if ord(i) < 128 else ' ' for i in text])

        # Strip 'RT ' from head of retweets, redundant
        if text.startswith('RT '):
            text = text[3:]

        # Ch newlines to spaces
        text = ''.join([' ' if c == '\n' else c for c in text])

        rt_count = result['retweet_count']

        yield {'_tweet_datetime': tweet_datetime,
               '_text': text,
               '_rt_count': rt_count}
Extract requested variables from Twitter API response. Yield each tweet
    one at a time with a generator. Available keys:

    [u'contributors', u'truncated', u'text', u'is_quote_status',
    u'in_reply_to_status_id', u'id', u'favorite_count', u'source',
    u'retweeted', u'coordinates', u'entities', u'in_reply_to_screen_name',
    u'in_reply_to_user_id', u'retweet_count', u'id_str', u'favorited',
    u'retweeted_status', u'user', u'geo', u'in_reply_to_user_id_str',
    u'possibly_sensitive', u'lang', u'created_at',
    u'in_reply_to_status_id_str', u'place', u'metadata']
    
Extract requested variables from Twitter API response. Yield each tweet
one at a time with a generator. Available keys.


Extract requested variables from Twitter API response . Yield each tweet one at a time with a generator . Available keys .
def parse_twitter_response(twitter_response, min_rts=500, strip_non_ascii=True):
    for result in twitter_response['statuses']:
        tweet_datetime = result['created_at']
        text = result['text'].encode('utf_8')
        if strip_non_ascii:
            text = ''.join([i if ord(i) < 128 else ' ' for i in text])
        if text.startswith('RT '):
            text = text[3:]
        text = ''.join([' ' if c == '\n' else c for c in text])
        rt_count = result['retweet_count']
        yield {'_tweet_datetime': tweet_datetime,
               '_text': text,
               '_rt_count': rt_count}
def parse_twitter_response ( twitter_response , min_rts = 500 , strip_non_ascii = True ) : for result in twitter_response [ 'statuses' ] : tweet_datetime = result [ 'created_at' ] text = result [ 'text' ] . encode ( 'utf_8' ) if strip_non_ascii : text = '' . join ( [ i if ord ( i ) < 128 else ' ' for i in text ] ) if text . startswith ( 'RT ' ) : text = text [ 3 : ] text = '' . join ( [ ' ' if c == '\n' else c for c in text ] ) rt_count = result [ 'retweet_count' ] yield { '_tweet_datetime' : tweet_datetime , '_text' : text , '_rt_count' : rt_count }
Extract requested variables from Twitter API response.
Extract requested variables from Twitter API response .
"""Extract requested variables from Twitter API response. Yield each tweet
    one at a time with a generator. Available keys:

    [u'contributors', u'truncated', u'text', u'is_quote_status',
    u'in_reply_to_status_id', u'id', u'favorite_count', u'source',
    u'retweeted', u'coordinates', u'entities', u'in_reply_to_screen_name',
    u'in_reply_to_user_id', u'retweet_count', u'id_str', u'favorited',
    u'retweeted_status', u'user', u'geo', u'in_reply_to_user_id_str',
    u'possibly_sensitive', u'lang', u'created_at',
    u'in_reply_to_status_id_str', u'place', u'metadata']
    """ # Strip 'RT ' from head of retweets, redundant # Ch newlines to spaces
twitter_response
min_rts
strip_non_ascii