updateInfoPleroma.py
def update_pleroma(self):
        """Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated.
        This includes:
        
        * Profile image (if exists)
        * Banner image (if exists)
        * Bio text
        * Screen name
        * Additional metadata fields
        
        :returns: None 
        """
        # Get the biggest resolution for the profile picture (400x400) instead of 'normal'
        if self.profile_image_url:
            profile_img_big = re.sub(r"normal", "400x400", self.profile_image_url)
            response = requests.get(profile_img_big, stream=True)
            if not response.ok:
                response.raise_for_status()
            response.raw.decode_content = True
            with open(self.avatar_path, 'wb') as outfile:
                shutil.copyfileobj(response.raw, outfile)

        if self.profile_banner_url:
            response = requests.get(self.profile_banner_url, stream=True)
            if not response.ok:
                response.raise_for_status()
            response.raw.decode_content = True
            with open(self.header_path, 'wb') as outfile:
                shutil.copyfileobj(response.raw, outfile)

        # Set it on Pleroma
        cred_url = self.pleroma_base_url + '/api/v1/accounts/update_credentials'

        # Construct fields
        fields = []
        for field_item in self.fields:
            field = (field_item['name'], field_item['value'])
            fields.append(field)
        data = {"note": self.bio_text,
                "display_name": self.display_name}

        if self.profile_image_url:
            data.update({"avatar": self.avatar_path})

        if self.profile_banner_url:
            data.update({"header": self.header_path})

        if len(fields) > 4:
            raise Exception("Maximum number of metadata fields is 4. Exiting...")
        for idx, (field_name, field_value) in enumerate(fields):
            data['fields_attributes[' + str(idx) + '][name]'] = field_name
            data['fields_attributes[' + str(idx) + '][value]'] = field_value

        if self.profile_image_url:
            avatar = open(self.avatar_path, 'rb')
            avatar_mime_type = guess_type(self.avatar_path)
            timestamp = str(datetime.now().timestamp())
            avatar_file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + mimetypes.guess_extension(
                avatar_mime_type)

        if self.profile_banner_url:
            header = open(self.header_path, 'rb')
            header_mime_type = guess_type(self.header_path)
            header_file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + mimetypes.guess_extension(
                header_mime_type)

        files = {}

        if self.profile_image_url:
            files.update(
                {"avatar": (avatar_file_name, avatar, avatar_mime_type)})
        if self.profile_banner_url:
            files.update(
                {"header": (header_file_name, header, header_mime_type)})
        response = requests.patch(cred_url, data, headers=self.header_pleroma, files=files)
        if not response.ok:
            response.raise_for_status()
        print("Updating profile:\t" + str(response))  # for debugging
        return
Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated.
        This includes:
        
        * Profile image (if exists)
        * Banner image (if exists)
        * Bio text
        * Screen name
        * Additional metadata fields
        
        :returns: None 
        
Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated.
This includes.

Profile image (if exists)
Banner image (if exists)
Bio text
Screen name
Additional metadata fields
Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated . This includes . Profile image ( if exists ) Banner image ( if exists ) Bio text Screen name Additional metadata fields
def update_pleroma(self):
        if self.profile_image_url:
            profile_img_big = re.sub(r"normal", "400x400", self.profile_image_url)
            response = requests.get(profile_img_big, stream=True)
            if not response.ok:
                response.raise_for_status()
            response.raw.decode_content = True
            with open(self.avatar_path, 'wb') as outfile:
                shutil.copyfileobj(response.raw, outfile)
        if self.profile_banner_url:
            response = requests.get(self.profile_banner_url, stream=True)
            if not response.ok:
                response.raise_for_status()
            response.raw.decode_content = True
            with open(self.header_path, 'wb') as outfile:
                shutil.copyfileobj(response.raw, outfile)
        cred_url = self.pleroma_base_url + '/api/v1/accounts/update_credentials'
        fields = []
        for field_item in self.fields:
            field = (field_item['name'], field_item['value'])
            fields.append(field)
        data = {"note": self.bio_text,
                "display_name": self.display_name}
        if self.profile_image_url:
            data.update({"avatar": self.avatar_path})
        if self.profile_banner_url:
            data.update({"header": self.header_path})
        if len(fields) > 4:
            raise Exception("Maximum number of metadata fields is 4. Exiting...")
        for idx, (field_name, field_value) in enumerate(fields):
            data['fields_attributes[' + str(idx) + '][name]'] = field_name
            data['fields_attributes[' + str(idx) + '][value]'] = field_value
        if self.profile_image_url:
            avatar = open(self.avatar_path, 'rb')
            avatar_mime_type = guess_type(self.avatar_path)
            timestamp = str(datetime.now().timestamp())
            avatar_file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + mimetypes.guess_extension(
                avatar_mime_type)
        if self.profile_banner_url:
            header = open(self.header_path, 'rb')
            header_mime_type = guess_type(self.header_path)
            header_file_name = "pleromapyupload_" + timestamp + "_" + random_string(10) + mimetypes.guess_extension(
                header_mime_type)
        files = {}
        if self.profile_image_url:
            files.update(
                {"avatar": (avatar_file_name, avatar, avatar_mime_type)})
        if self.profile_banner_url:
            files.update(
                {"header": (header_file_name, header, header_mime_type)})
        response = requests.patch(cred_url, data, headers=self.header_pleroma, files=files)
        if not response.ok:
            response.raise_for_status()
        print("Updating profile:\t" + str(response))  
        return
def update_pleroma ( self ) : if self . profile_image_url : profile_img_big = re . sub ( r"normal" , "400x400" , self . profile_image_url ) response = requests . get ( profile_img_big , stream = True ) if not response . ok : response . raise_for_status ( ) response . raw . decode_content = True with open ( self . avatar_path , 'wb' ) as outfile : shutil . copyfileobj ( response . raw , outfile ) if self . profile_banner_url : response = requests . get ( self . profile_banner_url , stream = True ) if not response . ok : response . raise_for_status ( ) response . raw . decode_content = True with open ( self . header_path , 'wb' ) as outfile : shutil . copyfileobj ( response . raw , outfile ) cred_url = self . pleroma_base_url + '/api/v1/accounts/update_credentials' fields = [ ] for field_item in self . fields : field = ( field_item [ 'name' ] , field_item [ 'value' ] ) fields . append ( field ) data = { "note" : self . bio_text , "display_name" : self . display_name } if self . profile_image_url : data . update ( { "avatar" : self . avatar_path } ) if self . profile_banner_url : data . update ( { "header" : self . header_path } ) if len ( fields ) > 4 : raise Exception ( "Maximum number of metadata fields is 4. Exiting..." ) for idx , ( field_name , field_value ) in enumerate ( fields ) : data [ 'fields_attributes[' + str ( idx ) + '][name]' ] = field_name data [ 'fields_attributes[' + str ( idx ) + '][value]' ] = field_value if self . profile_image_url : avatar = open ( self . avatar_path , 'rb' ) avatar_mime_type = guess_type ( self . avatar_path ) timestamp = str ( datetime . now ( ) . timestamp ( ) ) avatar_file_name = "pleromapyupload_" + timestamp + "_" + random_string ( 10 ) + mimetypes . guess_extension ( avatar_mime_type ) if self . profile_banner_url : header = open ( self . header_path , 'rb' ) header_mime_type = guess_type ( self . header_path ) header_file_name = "pleromapyupload_" + timestamp + "_" + random_string ( 10 ) + mimetypes . guess_extension ( header_mime_type ) files = { } if self . profile_image_url : files . update ( { "avatar" : ( avatar_file_name , avatar , avatar_mime_type ) } ) if self . profile_banner_url : files . update ( { "header" : ( header_file_name , header , header_mime_type ) } ) response = requests . patch ( cred_url , data , headers = self . header_pleroma , files = files ) if not response . ok : response . raise_for_status ( ) print ( "Updating profile:\t" + str ( response ) ) return
Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated.
Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated .
"""Update the Pleroma user info with the one retrieved from Twitter when the User object was instantiated.
        This includes:
        
        * Profile image (if exists)
        * Banner image (if exists)
        * Bio text
        * Screen name
        * Additional metadata fields
        
        :returns: None 
        """ # Get the biggest resolution for the profile picture (400x400) instead of 'normal' # Set it on Pleroma # Construct fields # for debugging
None
self