def attach_text(self, post, text): """ Attach plain text to the given post. Keep all the previously embedded images intact. :param post: post instance. :param text: new post text. """ post.content = html_parsers.embed_images( text, html_parsers.list_images(post.content))
def update_about_me_photo(self, photo_path): """ Update about me page with the author photo. :param photo_path: path to the new about me photo. """ page = self.get_about_me_page() res = self._upload_media(photo_path) content = html_parsers.delete_images(page.content) page.content = html_parsers.embed_images(content, res["url"]) self.publish_post(page) self._cache_user_photo()
def update_about_me_bio(self, text): """ Update about me page with informations about the author. :param text: content of the page, eg. the author bio. """ page = self.get_about_me_page() images = html_parsers.list_images(page.content) if len(images) > 0: text = html_parsers.embed_images(text, images[0]) page.content = text self.publish_post(page)
def attach_images(self, post): """ Upload all images stored on the 'post_images' list to the server and attach them to the given post. :param post: instance of the post. """ image_urls = [] for image_path in self.post_images: # send image to the server image_urls.append(self._upload_media(image_path)["url"]) post.content = html_parsers.embed_images(post.content, image_urls) self.post_images.clear()