This repository has been archived on 2024-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
Auberge_Vagabonde/gravesong.py
Michel Roux d3a7ac0fc2
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Back to python + Gravesong
2022-01-18 20:43:45 +00:00

42 lines
1.3 KiB
Python

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)