Exemplo n.º 1
0
    def get_tweets_for_keyword(self, keyword, count=100, result_type="recent"):

        keyword = keyword + " -filter:retweets"

        tweets = Cursor(self.twitter_client.search,
                        q=keyword,
                        count=count,
                        lang='en',
                        tweet_mode='extended',
                        result_type=result_type).items(count)

        # for tweet_info in Cursor(self.twitter_client.search, q=keyword, count=count, lang = 'en', tweet_mode='extended').items(count):
        #     if 'retweeted_status' in dir(tweet_info):
        #         tweet=tweet_info.retweeted_status.full_text
        #     else:
        #         tweet=tweet_info.full_text
        #     tweets.append(tweet)

        dates = []
        tweets = []

        for tweet in Cursor(self.twitter_client.search,
                            q=keyword,
                            count=count,
                            lang='en',
                            tweet_mode='extended').items(count):
            dates.append(tweet.created_at)
            tweets.append(tweet.full_text)

        df = pd.DataFrame(data=np.array(tweets), columns=["tweets"])
        df['date'] = np.array(dates)

        return df, tweets
 def get_tweets(self, num_tweet=0):
     #return tweet by the specific user or self
     tweets = []
     if num_tweet == 0:
         tweets = Cursor(self.twitter_client.user_timeline,
                         id=self.twitter_user)
     else:
         for tweet in Cursor(self.twitter_client.user_timeline,
                             id=self.twitter_user).items(num_tweet):
             tweets.append(tweet)
     return tweets