def check_for_update(filters, last): tweets = TwitterRpcMethods.do_query(filters) if last: last = datetime.fromtimestamp(last) tweets = tweets.filter(created_at__gt=last) tweet_ids = tweets.values_list("id", flat=True) keywords = Keyword.get_all_in_tweets(tweet_ids) cloud = KeywordCloud(keywords) return [str(tweet_id) for tweet_id in tweet_ids]
def search_tweets(filters): tweets = TwitterRpcMethods.do_query(filters) exclude = [] for filter in filters: if filter["type"] == "keyword": exclude.append(filter["value"]) elif filter["type"] == "user": exclude.append("@" + filter["value"]) print urlencode(filter) tweet_ids = tweets.values_list("id", flat=True) keywords = Keyword.get_all_in_tweets(tweet_ids) cloud = KeywordCloud(keywords, exclude=exclude) return {"tweet_ids": [str(tweet_id) for tweet_id in tweet_ids or []], "cloud": cloud}
def cloud(filters): tweets = TwitterRpcMethods.do_query(filters) tweet_ids = tweets.values_list("id", flat=True) keywords = Keyword.get_all_in_tweets(tweet_ids) cloud = KeywordCloud(keywords, num_keywords=100) return cloud