mirror of
https://github.com/captn3m0/google-sre-ebook.git
synced 2024-07-26 20:43:02 +00:00
Gets an epub generated
- no image support yet
This commit is contained in:
parent
b8f611683f
commit
c1778dcd71
20
.editorconfig
Normal file
20
.editorconfig
Normal file
@ -0,0 +1,20 @@
|
||||
;
|
||||
; Global Editor Config for Adaptive Labbers
|
||||
;
|
||||
; This is an ini style configuration. See http://editorconfig.org/ for more information on this file.
|
||||
;
|
||||
; Top level editor config.
|
||||
root = true
|
||||
; Always use Unix style new lines with new line ending on every file and trim whitespace
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
; Python: PEP8 defines 4 spaces for indentation
|
||||
[*.py]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
; Salt state files, YAML format, 2 spaces
|
||||
[*.sls, *.yaml, *.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
2
build/.gitignore
vendored
Normal file
2
build/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
25
generate.py
Normal file
25
generate.py
Normal file
@ -0,0 +1,25 @@
|
||||
from bs4 import BeautifulSoup
|
||||
import pypub
|
||||
|
||||
epub = pypub.Epub('Site Reliability Engineering')
|
||||
|
||||
def setup_toc():
|
||||
soup = BeautifulSoup(open('./html/index.html'), 'html.parser')
|
||||
links = soup.select('.content a ')
|
||||
for link in links:
|
||||
print(link['href'])
|
||||
add_chapter_file(link['href'], link.get_text())
|
||||
|
||||
epub.create_epub('./build')
|
||||
|
||||
def add_chapter_file(href, title):
|
||||
file_path = href.replace('/sre/book/', 'html/')
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
contents = f.read()
|
||||
chapter_soup = BeautifulSoup(contents, 'html.parser')
|
||||
chapter_html = chapter_soup.select_one('.content').prettify("utf-8")
|
||||
chapter = pypub.create_chapter_from_string(chapter_html, url=None, title=title)
|
||||
epub.add_chapter(chapter)
|
||||
|
||||
setup_toc()
|
9
requirements.txt
Normal file
9
requirements.txt
Normal file
@ -0,0 +1,9 @@
|
||||
appdirs==1.4.0
|
||||
beautifulsoup4==4.5.3
|
||||
Jinja2==2.9.5
|
||||
MarkupSafe==0.23
|
||||
packaging==16.8
|
||||
pyparsing==2.1.10
|
||||
pypub==1.4
|
||||
requests==2.13.0
|
||||
six==1.10.0
|
Loading…
Reference in New Issue
Block a user