import bs4 import executor import pypub import requests @executor.executor def process(metadata, output_dir): book = pypub.Epub("Gravesong", *metadata) response = requests.post( "https://wanderinginn.com/wp-pass.php", data={"post_password": "Iwalkedameadowweary", "Submit": "Enter"}, headers={"Referer": "https://wanderinginn.com/2022/01/11/gravesong/"}, ) html = bs4.BeautifulSoup(response.content, "html.parser") entry_content = html.select_one("div.entry-content") content_imgs = entry_content.find_all("img") for content_img in content_imgs: content_img.decompose() chapter_title = "Introduction" chapter_content = "" for paragraph in entry_content.children: if paragraph.name == "h1": print(f"Gravesong - {chapter_title}") book.add_chapter( pypub.create_chapter_from_string(chapter_content, chapter_title) ) chapter_title = paragraph.get_text() elif paragraph.name == "p": chapter_content += paragraph.prettify() print(f"Gravesong - {chapter_title}") book.add_chapter(pypub.create_chapter_from_string(chapter_content, chapter_title)) print("Gravesong - Book") book.create_epub(output_dir)