Ejemplo n.º 1
0
    def get_tweets_by_user_id_time_restricted(self,
                                              user_id: str) -> List[Tweet]:
        """
        Return a list of tweet with user_id that matches the given user_id
        since a certain time

        @param user_id the id of the user to retrieve tweets from

        @return a list of tweets by the given user
        """
        from_date = datetime.today() + relativedelta(months=-12)
        # from_date = datetime(2020, 6, 30)
        tweet_doc_list = self.collection.find({
            "$and": [{
                "user_id": bson.int64.Int64(user_id)
            }, {
                "created_at": {
                    "$gte": from_date
                }
            }]
        })
        tweets = []
        for doc in tweet_doc_list:
            tweets.append(Tweet.fromDict(doc))
        return tweets
Ejemplo n.º 2
0
    def get_retweets_of_user_by_user_id(self, user_id: str) -> List[Tweet]:
        retweet_doc_list = self.collection.find(
            {"retweet_user_id": bson.int64.Int64(user_id)})

        retweets = []
        for doc in retweet_doc_list:
            retweets.append(Tweet.fromDict(doc))

        return retweets
Ejemplo n.º 3
0
    def get_tweet_by_id(self, id: str) -> Tweet:
        """
        Return tweet with id that matches the given id

        @param id the id of the tweet to get

        @return the Tweet object corresponding to the tweet id, or none if no
            tweet matches the given id
        """
        tweet_doc = self.collection.find_one({"id": bson.int64.Int64(id)})
        if tweet_doc is not None:
            return Tweet.fromDict(tweet_doc)
        else:
            return None
Ejemplo n.º 4
0
    def get_tweets_by_user_id(self, user_id: str) -> List[Tweet]:
        """
        Return a list of tweet with user_id that matches the given user_id

        @param user_id the id of the user to retrieve tweets from

        @return a list of tweets by the given user
        """

        tweet_doc_list = self.collection.find(
            {"user_id": bson.int64.Int64(user_id)})

        tweets = []
        for doc in tweet_doc_list:
            tweets.append(Tweet.fromDict(doc))

        return tweets
Ejemplo n.º 5
0
    def get_retweets_of_user_by_user_id_time_restricted(
            self, user_id: str) -> List[Tweet]:

        from_date = datetime(2020, 6, 30)
        retweet_doc_list = self.collection.find({
            "$and": [{
                "retweet_user_id": bson.int64.Int64(user_id)
            }, {
                "created_at": {
                    "$gte": from_date
                }
            }]
        })
        retweets = []
        for doc in retweet_doc_list:
            retweets.append(Tweet.fromDict(doc))

        return retweets