updateInfoPleroma.py
def post_pleroma(self, tweet_id: str, tweet_text: str, poll: dict) -> str:
        """Post the given text to the Pleroma instance associated with the User object
        
        :param tweet_id: It will be used to link to the Twitter status if 'signature' is True and to find related media
        :type tweet_id: str
        :param tweet_text: Literal text to use when creating the post.
        :type tweet_text: str
        :returns: id of post
        :rtype: str
        """
        # TODO: transform twitter links to nitter links, if self.nitter 'true' in resolved shortened urls
        pleroma_post_url = self.pleroma_base_url + '/api/v1/statuses'
        pleroma_media_url = self.pleroma_base_url + '/api/v1/media'

        tweet_folder = os.path.join(self.tweets_temp_path, tweet_id)
        media_files = os.listdir(tweet_folder)
        media_ids = []
        if self.media_upload:
            for file in media_files:
                media_file = open(os.path.join(tweet_folder, file), 'rb')
                media_size = os.stat(os.path.join(tweet_folder, file)).st_size
                mime_type = guess_type(os.path.join(tweet_folder, file))
                timestamp = str(datetime.now().timestamp())
                file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + \
                            mimetypes.guess_extension(mime_type)
                file_description = (file_name, media_file, mime_type)
                files = {"file": file_description}
                response = requests.post(pleroma_media_url, headers=self.header_pleroma, files=files)
                if not response.ok:
                    response.raise_for_status()
                try:
                    media_ids.append(json.loads(response.text)['id'])
                except (KeyError, JSONDecodeError):
                    print("Error uploading media:\t" + str(response.text))
                    pass

        if self.signature:
            signature = '\n\n 🐦🔗: ' + self.twitter_url + '/status/' + tweet_id
            tweet_text = tweet_text + signature

        data = {"status": tweet_text,
                "sensitive": str(self.sensitive),
                "visibility": self.visibility,
                "media_ids[]": media_ids}

        if poll:
            data.update({"poll[options][]": poll['options'],
                         "poll[expires_in]": poll['expires_in']})

        if hasattr(self, "rich_text"):
            if self.rich_text:
                data.update({"content_type": self.content_type})
        response = requests.post(pleroma_post_url, data, headers=self.header_pleroma)
        if not response.ok:
            response.raise_for_status()
        print("Post in Pleroma:\t" + str(response))
        post_id = json.loads(response.text)['id']
        return post_id
Post the given text to the Pleroma instance associated with the User object
        
        :param tweet_id: It will be used to link to the Twitter status if 'signature' is True and to find related media
        :type tweet_id: str
        :param tweet_text: Literal text to use when creating the post.
        :type tweet_text: str
        :returns: id of post
        :rtype: str
        
Post the given text to the Pleroma instance associated with the User object
Post the given text to the Pleroma instance associated with the User object
def post_pleroma(self, tweet_id: str, tweet_text: str, poll: dict) -> str:
        pleroma_post_url = self.pleroma_base_url + '/api/v1/statuses'
        pleroma_media_url = self.pleroma_base_url + '/api/v1/media'
        tweet_folder = os.path.join(self.tweets_temp_path, tweet_id)
        media_files = os.listdir(tweet_folder)
        media_ids = []
        if self.media_upload:
            for file in media_files:
                media_file = open(os.path.join(tweet_folder, file), 'rb')
                media_size = os.stat(os.path.join(tweet_folder, file)).st_size
                mime_type = guess_type(os.path.join(tweet_folder, file))
                timestamp = str(datetime.now().timestamp())
                file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + \
                            mimetypes.guess_extension(mime_type)
                file_description = (file_name, media_file, mime_type)
                files = {"file": file_description}
                response = requests.post(pleroma_media_url, headers=self.header_pleroma, files=files)
                if not response.ok:
                    response.raise_for_status()
                try:
                    media_ids.append(json.loads(response.text)['id'])
                except (KeyError, JSONDecodeError):
                    print("Error uploading media:\t" + str(response.text))
                    pass
        if self.signature:
            signature = '\n\n 🐦🔗: ' + self.twitter_url + '/status/' + tweet_id
            tweet_text = tweet_text + signature
        data = {"status": tweet_text,
                "sensitive": str(self.sensitive),
                "visibility": self.visibility,
                "media_ids[]": media_ids}
        if poll:
            data.update({"poll[options][]": poll['options'],
                         "poll[expires_in]": poll['expires_in']})
        if hasattr(self, "rich_text"):
            if self.rich_text:
                data.update({"content_type": self.content_type})
        response = requests.post(pleroma_post_url, data, headers=self.header_pleroma)
        if not response.ok:
            response.raise_for_status()
        print("Post in Pleroma:\t" + str(response))
        post_id = json.loads(response.text)['id']
        return post_id
def post_pleroma ( self , tweet_id : str , tweet_text : str , poll : dict ) -> str : pleroma_post_url = self . pleroma_base_url + '/api/v1/statuses' pleroma_media_url = self . pleroma_base_url + '/api/v1/media' tweet_folder = os . path . join ( self . tweets_temp_path , tweet_id ) media_files = os . listdir ( tweet_folder ) media_ids = [ ] if self . media_upload : for file in media_files : media_file = open ( os . path . join ( tweet_folder , file ) , 'rb' ) media_size = os . stat ( os . path . join ( tweet_folder , file ) ) . st_size mime_type = guess_type ( os . path . join ( tweet_folder , file ) ) timestamp = str ( datetime . now ( ) . timestamp ( ) ) file_name = "pleromapyupload_" + timestamp + "_" + random_string ( 10 ) + mimetypes . guess_extension ( mime_type ) file_description = ( file_name , media_file , mime_type ) files = { "file" : file_description } response = requests . post ( pleroma_media_url , headers = self . header_pleroma , files = files ) if not response . ok : response . raise_for_status ( ) try : media_ids . append ( json . loads ( response . text ) [ 'id' ] ) except ( KeyError , JSONDecodeError ) : print ( "Error uploading media:\t" + str ( response . text ) ) pass if self . signature : signature = '\n\n 🐦🔗: ' + sel . witt e r_url + '/s a us/' + twe t id tweet_text = tweet_text + signature data = { "status" : tweet_text , "sensitive" : str ( self . sensitive ) , "visibility" : self . visibility , "media_ids[]" : media_ids } if poll : data . update ( { "poll[options][]" : poll [ 'options' ] , "poll[expires_in]" : poll [ 'expires_in' ] } ) if hasattr ( self , "rich_text" ) : if self . rich_text : data . update ( { "content_type" : self . content_type } ) response = requests . post ( pleroma_post_url , data , headers = self . header_pleroma ) if not response . ok : response . raise_for_status ( ) print ( "Post in Pleroma:\t" + str ( response ) ) post_id = json . loads ( response . text ) [ 'id' ] return post_id
Post the given text to the Pleroma instance associated with the User object
Post the given text to the Pleroma instance associated with the User object
"""Post the given text to the Pleroma instance associated with the User object
        
        :param tweet_id: It will be used to link to the Twitter status if 'signature' is True and to find related media
        :type tweet_id: str
        :param tweet_text: Literal text to use when creating the post.
        :type tweet_text: str
        :returns: id of post
        :rtype: str
        """ # TODO: transform twitter links to nitter links, if self.nitter 'true' in resolved shortened urls
id of post
id of post
str
self
tweet_id
str
It will be used to link to the Twitter status if 'signature' is True and to find related media
It will be used to link to the Twitter status if ' signature ' is True and to find related media
tweet_text
str
Literal text to use when creating the post.
Literal text to use when creating the post .
poll
dict