예제 #1
0
def get_tweets(query, result_type, max_tweets):
    # Search the Twitter API for the given title
    twitter_client = Twitter(CONFIG['twitter'])
    tweet_data = twitter_client.search(
        "\"%s\" movie -download -stream -#nw -#nowwatching -RT" % (query, ),
        result_type=result_type,
        count=max_tweets)

    if DEBUG:
        print "Retrieved %d tweets (with result type %s)." % (len(tweet_data),
                                                              result_type)

    # if DEBUG:
    #     print json.dumps(tweet_data[0], sort_keys=True, indent=4, separators=(',', ': '))

    # Build simple Twitter objects
    tweets = map(Tweet, tweet_data)

    # Add a filtered version of the tweet text
    pattern = re.compile(query.replace(" ", " ?"), re.I)
    for tweet in tweets:
        tweet.sentiment = get_cached_tweet_sentiment(tweet.id)
        tweet.filtered_text = pattern.sub('', tweet.text)

    return tweets
예제 #2
0
def add_tweetstream(body):

    # convert the query to a search query string
    s = Twitter.search(body["query"])

    twitter.TweetStream(station_id=body["station_id"],
                        stream_query=str(s)).put()
    return body
예제 #3
0
def add_tweetstream(body):
    
    # convert the query to a search query string
    s = Twitter.search( body["query"] )
    
    twitter.TweetStream(station_id = body["station_id"],
                        stream_query = str(s) ).put()
    return body
예제 #4
0
def refresh_tweetstream(tweetstream_key):

    log.info("refreshing tweetstream %s" % tweetstream_key)

    # the stream to update
    stream = twitter.TweetStream.get_by_urlsafe(tweetstream_key)

    # refresh the query
    s = Twitter.search(qs=stream.stream_query)  # based on the query string
    s.fetch(process_tweets, {"stream-key": tweetstream_key})
예제 #5
0
def refresh_tweetstream( tweetstream_key ):    
    
    log.info("refreshing tweetstream %s" % tweetstream_key  )
        
    # the stream to update        
    stream = twitter.TweetStream.get_by_urlsafe(tweetstream_key)    

    # refresh the query
    s = Twitter.search( qs = stream.stream_query ) # based on the query string
    s.fetch(process_tweets, {"stream-key":tweetstream_key})
예제 #6
0
def get_tweets(query, result_type, max_tweets):
    # Search the Twitter API for the given title
    twitter_client = Twitter(CONFIG['twitter'])
    tweet_data = twitter_client.search("\"%s\" movie -download -stream -#nw -#nowwatching -RT" % (query,), result_type=result_type, count=max_tweets)
    
    if DEBUG: print "Retrieved %d tweets (with result type %s)." % (len(tweet_data), result_type)
    
    # if DEBUG:
    #     print json.dumps(tweet_data[0], sort_keys=True, indent=4, separators=(',', ': '))
    
    # Build simple Twitter objects
    tweets = map(Tweet, tweet_data)
    
    # Add a filtered version of the tweet text
    pattern = re.compile(query.replace(" ", " ?"), re.I)
    for tweet in tweets:
        tweet.sentiment = get_cached_tweet_sentiment(tweet.id)
        tweet.filtered_text = pattern.sub('', tweet.text)
    
    return tweets