def get_user_tweets(self, target, days, party): """ Get a specific user's tweets from the last X number of days, and associate the tweets with specific paryy :param target: Target name :param days: Number of days to query back :param party: The party associated with the person queried :return: Array of tweets for the specific person """ tweets = [] end_date = datetime.utcnow() - timedelta(days=days) for status in Cursor(self._api.user_timeline, id=target, count=1000, tweet_mode='extended').items(): tweet = Tweet() tweet.load_from_status(status, party) tweets.append(tweet) if status.created_at < end_date: break return tweets
def get_search_tweets(self, country_code, days, target): """ Free text tweets search :param country_code: (Optional) Twitter's internal ID for the country, set None if we don't want this filter :param days: Number of days to query back from Twitter :param target: The search query we want to invoke against Twitter :return: Array of tweets with party set to Unknown """ tweets = [] end_date = datetime.utcnow() - timedelta(days=days) query = target if country_code is not None: query = 'place:{} AND {}'.format(country_code, target) for status in Cursor(self._api.search, q=query, count=1000, tweet_mode='extended').items(): if status.created_at > end_date: tweet = Tweet() tweet.load_from_status(status, Parties.Unknown) tweets.append(tweet) return tweets