updateInfoPleroma.py
def _get_tweets(self, version: str, tweet_id=None):
        """Gathers last 'max_tweets' tweets from the user and returns them as an dict
        :param version: Twitter API version to use to retrieve the tweets
        :type version: string
        :param tweet_id: Tweet ID to retrieve
        :type tweet_id: int

        :returns: last 'max_tweets' tweets
        :rtype: dict
        """
        if version == 'v1.1':
            if tweet_id:
                twitter_status_url = f"{self.twitter_base_url}/statuses/show.json?id={str(tweet_id)}"
                response = requests.get(twitter_status_url, headers=self.header_twitter)
                if not response.ok:
                    response.raise_for_status()
                tweet = json.loads(response.text)
                return tweet
            else:
                twitter_status_url = self.twitter_base_url + '/statuses/user_timeline.json?screen_name=' + \
                                     self.twitter_username + '&count=' + str(self.max_tweets) + '&include_rts=true'
                response = requests.get(twitter_status_url, headers=self.header_twitter)
                if not response.ok:
                    response.raise_for_status()
                tweets = json.loads(response.text)
                return tweets
        elif version == 'v2':
            params = {}
            if tweet_id:
                url = f"{self.twitter_base_url_v2}/tweets/{tweet_id}"
            else:
                url = f"{self.twitter_base_url_v2}/tweets/search/recent"  # this only gets tweets from last week
                params.update({"max_results": self.max_tweets,
                               "query": "from:" + self.twitter_username})
            # Tweet number must be between 10 and 100
            if not (100 >= self.max_tweets > 10):
                raise ValueError(f"max_tweets must be between 10 and 100. max_tweets: {self.max_tweets}")

            params.update({"poll.fields": "duration_minutes,end_datetime,id,options,voting_status",
                           "media.fields": "duration_ms,height,media_key,"
                                           "preview_image_url,"
                                           "type,"
                                           "url,"
                                           "width,"
                                           "public_metrics",
                           "expansions": "attachments.poll_ids,"
                                         "attachments.media_keys,"
                                         "author_id,"
                                         "entities.mentions.username,"
                                         "geo.place_id,"
                                         "in_reply_to_user_id,"
                                         "referenced_tweets.id,"
                                         "referenced_tweets.id.author_id",
                           "tweet.fields": "attachments,"
                                           "author_id,"
                                           "context_annotations,"
                                           "conversation_id,"
                                           "created_at,"
                                           "entities,"
                                           "geo,id,"
                                           "in_reply_to_user_id,"
                                           "lang,"
                                           "public_metrics,"
                                           "possibly_sensitive,"
                                           "referenced_tweets,"
                                           "source,"
                                           "text,"
                                           "withheld"
                           })
            response = requests.get(url, headers=self.header_twitter, params=params)
            if not response.ok:
                response.raise_for_status()
            tweets_v2 = json.loads(response.text)
            return tweets_v2
        else:
            raise ValueError(f"API version not supported: {version}")
Gathers last 'max_tweets' tweets from the user and returns them as an dict
        :param version: Twitter API version to use to retrieve the tweets
        :type version: string
        :param tweet_id: Tweet ID to retrieve
        :type tweet_id: int

        :returns: last 'max_tweets' tweets
        :rtype: dict
        
Gathers last 'max_tweets' tweets from the user and returns them as an dict
Gathers last ' max_tweets ' tweets from the user and returns them as an dict
def _get_tweets(self, version: str, tweet_id=None):
        if version == 'v1.1':
            if tweet_id:
                twitter_status_url = f"{self.twitter_base_url}/statuses/show.json?id={str(tweet_id)}"
                response = requests.get(twitter_status_url, headers=self.header_twitter)
                if not response.ok:
                    response.raise_for_status()
                tweet = json.loads(response.text)
                return tweet
            else:
                twitter_status_url = self.twitter_base_url + '/statuses/user_timeline.json?screen_name=' + \
                                     self.twitter_username + '&count=' + str(self.max_tweets) + '&include_rts=true'
                response = requests.get(twitter_status_url, headers=self.header_twitter)
                if not response.ok:
                    response.raise_for_status()
                tweets = json.loads(response.text)
                return tweets
        elif version == 'v2':
            params = {}
            if tweet_id:
                url = f"{self.twitter_base_url_v2}/tweets/{tweet_id}"
            else:
                url = f"{self.twitter_base_url_v2}/tweets/search/recent"  
                params.update({"max_results": self.max_tweets,
                               "query": "from:" + self.twitter_username})
            if not (100 >= self.max_tweets > 10):
                raise ValueError(f"max_tweets must be between 10 and 100. max_tweets: {self.max_tweets}")
            params.update({"poll.fields": "duration_minutes,end_datetime,id,options,voting_status",
                           "media.fields": "duration_ms,height,media_key,"
                                           "preview_image_url,"
                                           "type,"
                                           "url,"
                                           "width,"
                                           "public_metrics",
                           "expansions": "attachments.poll_ids,"
                                         "attachments.media_keys,"
                                         "author_id,"
                                         "entities.mentions.username,"
                                         "geo.place_id,"
                                         "in_reply_to_user_id,"
                                         "referenced_tweets.id,"
                                         "referenced_tweets.id.author_id",
                           "tweet.fields": "attachments,"
                                           "author_id,"
                                           "context_annotations,"
                                           "conversation_id,"
                                           "created_at,"
                                           "entities,"
                                           "geo,id,"
                                           "in_reply_to_user_id,"
                                           "lang,"
                                           "public_metrics,"
                                           "possibly_sensitive,"
                                           "referenced_tweets,"
                                           "source,"
                                           "text,"
                                           "withheld"
                           })
            response = requests.get(url, headers=self.header_twitter, params=params)
            if not response.ok:
                response.raise_for_status()
            tweets_v2 = json.loads(response.text)
            return tweets_v2
        else:
            raise ValueError(f"API version not supported: {version}")
def _get_tweets ( self , version : str , tweet_id = None ) : if version == 'v1.1' : if tweet_id : twitter_status_url = f"{self.twitter_base_url}/statuses/show.json?id={str(tweet_id)}" response = requests . get ( twitter_status_url , headers = self . header_twitter ) if not response . ok : response . raise_for_status ( ) tweet = json . loads ( response . text ) return tweet else : twitter_status_url = self . twitter_base_url + '/statuses/user_timeline.json?screen_name=' + self . twitter_username + '&count=' + str ( self . max_tweets ) + '&include_rts=true' response = requests . get ( twitter_status_url , headers = self . header_twitter ) if not response . ok : response . raise_for_status ( ) tweets = json . loads ( response . text ) return tweets elif version == 'v2' : params = { } if tweet_id : url = f"{self.twitter_base_url_v2}/tweets/{tweet_id}" else : url = f"{self.twitter_base_url_v2}/tweets/search/recent" params . update ( { "max_results" : self . max_tweets , "query" : "from:" + self . twitter_username } ) if not ( 100 >= self . max_tweets > 10 ) : raise ValueError ( f"max_tweets must be between 10 and 100. max_tweets: {self.max_tweets}" ) params . update ( { "poll.fields" : "duration_minutes,end_datetime,id,options,voting_status" , "media.fields" : "duration_ms,height,media_key," "preview_image_url," "type," "url," "width," "public_metrics" , "expansions" : "attachments.poll_ids," "attachments.media_keys," "author_id," "entities.mentions.username," "geo.place_id," "in_reply_to_user_id," "referenced_tweets.id," "referenced_tweets.id.author_id" , "tweet.fields" : "attachments," "author_id," "context_annotations," "conversation_id," "created_at," "entities," "geo,id," "in_reply_to_user_id," "lang," "public_metrics," "possibly_sensitive," "referenced_tweets," "source," "text," "withheld" } ) response = requests . get ( url , headers = self . header_twitter , params = params ) if not response . ok : response . raise_for_status ( ) tweets_v2 = json . loads ( response . text ) return tweets_v2 else : raise ValueError ( f"API version not supported: {version}" )
Gathers last 'max_tweets' tweets from the user and returns them as an dict
Gathers last ' max_tweets ' tweets from the user and returns them as an dict
"""Gathers last 'max_tweets' tweets from the user and returns them as an dict
        :param version: Twitter API version to use to retrieve the tweets
        :type version: string
        :param tweet_id: Tweet ID to retrieve
        :type tweet_id: int

        :returns: last 'max_tweets' tweets
        :rtype: dict
        """ # this only gets tweets from last week # Tweet number must be between 10 and 100
last 'max_tweets' tweets
last ' max_tweets ' tweets
dict
self
version
str
Twitter API version to use to retrieve the tweets
Twitter API version to use to retrieve the tweets
tweet_id
Tweet ID to retrieve
Tweet ID to retrieve