Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
obar1 committed Apr 3, 2024
1 parent 32c0174 commit 520d013
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 44 deletions.
9 changes: 9 additions & 0 deletions zero_to_one_hundred/models/meta_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def __init__(
self.path_epub = f"{self.contents_path}/{self.isbn}.epub"
self.path_pdf = f"{self.contents_path}/{self.isbn}.pdf"
self.path_img = f"{self.contents_path}/{self.isbn}.png"
self.path_epub_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.epub")
self.path_pdf_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.pdf")
self.path_img_as_md = self.path_as_md(f"./{self.isbn}/{self.isbn}.png")

def asMarkDown(self):
return f"MetaBook {self.http_url}, {self.isbn} {self.contents_path}"
Expand Down Expand Up @@ -129,3 +132,9 @@ def write_pdf(self, fn):

def write_splitter_pdf(self, fn, split_pdf_pages):
self.persist_fs.write_splitter_pdf(fn, split_pdf_pages)

def path_as_md(self, a_path):
"""
use relative path and convert " " to %20
"""
return a_path.replace(" ", "%20")
17 changes: 8 additions & 9 deletions zero_to_one_hundred/models/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(
def __repr__(self):
return f"Toc {self.readme_md}, {self.meta_books}"


@classmethod
def build_from_dirs(
cls, config_map, persist_fs, process_fs, dirs: List[str]
Expand All @@ -45,7 +44,6 @@ def build_from_dirs(
return res

def asMarkDown(self):

def flatten_meta_book(meta_book: MetaBook):
print(f"flatten_meta_book {meta_book}")
json = meta_book.read_json().replace(
Expand All @@ -60,30 +58,31 @@ def flatten_meta_book(meta_book: MetaBook):
res = "|".join(
[
f'<span style="color:blue">**{meta_book.isbn}**</span>',
f"![`img`]({MarkdownRenderer.render_path(meta_book.path_img, meta_book.contents_path)})",
f"[`epub`]({MarkdownRenderer.render_path(meta_book.path_epub, meta_book.contents_path)})",
f"[`pdf`]({MarkdownRenderer.render_path(meta_book.path_pdf, meta_book.contents_path)})",
f"![`img`]({meta_book.path_img_as_md})",
f"[`epub`]({meta_book.path_epub_as_md})",
f"[`pdf`]({meta_book.path_pdf_as_md})",
f"{json}",
f"{status}",
]
)
return res

return "|" + res + "|" + " "

flattened_meta_book = [flatten_meta_book(mb) for mb in self.meta_books]
backslash_n_char = "\\n"
backslash_n_char = "\n"

md = []
md.append(
f"""
# TOC
## `{len(self.meta_books)}` books
### {self.process_fs.get_now()}
| ISBN | | | | `json-contents` | `status` |
| ISBN | img | epub | pdf | `json-contents` | `status` |
|--- |--- |--- |--- |--- |--- |
{backslash_n_char.join(flattened_meta_book)}
"""
)
return backslash_n_char.join(md)
return md

def write(self):
md = self.asMarkDown()
Expand Down
13 changes: 5 additions & 8 deletions zero_to_one_hundred/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ def get_datacamp_config_map(
env_datacamp_map_yaml, get_datacamp_map_yaml_path, persist_fs
):
return ZTOHConfigMap(persist_fs)


@pytest.fixture
def get_factory(env_map_yaml, persist_fs, process_fs):
return ZTOHFactory(
get_config_map, persist_fs, process_fs
)
return ZTOHFactory(get_config_map, persist_fs, process_fs)


@pytest.fixture
def get_factory_provider(env_map_yaml, persist_fs, process_fs):
return ZTOHFactoryProvider(persist_fs, process_fs)
Expand All @@ -159,8 +161,3 @@ def str_relaxed(s1):
remove = string.whitespace
mapping = {ord(c): None for c in remove}
return s1.translate(mapping)


@pytest.fixture
def get_factory_provider(env_map_yaml, persist_fs, process_fs):
return ZTOHFactoryProvider(persist_fs, process_fs)
4 changes: 3 additions & 1 deletion zero_to_one_hundred/tests/test_create_section_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

@patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor")
def test_process(get_config_map, get_factory, http_url):
actual: CreateSectionProcessor = get_factory.get_processor([None, "create_section", http_url])
actual: CreateSectionProcessor = get_factory.get_processor(
[None, "create_section", http_url]
)
for p in actual:
p.process()
5 changes: 3 additions & 2 deletions zero_to_one_hundred/tests/test_done_section_processor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from unittest.mock import patch
from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory
from zero_to_one_hundred.processors.done_section_processor import DoneSectionProcessor


@patch("zero_to_one_hundred.factories.ztoh_factory.ZTOHFactory.get_processor")
def test_process(get_config_map, get_factory, http_url):
actual: DoneSectionProcessor =get_factory.get_processor([None, "done_section", http_url])
actual: DoneSectionProcessor = get_factory.get_processor(
[None, "done_section", http_url]
)
for p in actual:
p.process()
4 changes: 1 addition & 3 deletions zero_to_one_hundred/tests/test_help_processor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from zero_to_one_hundred.processors.help_processor import HelpProcessor


def test_process(
get_factory
):
def test_process(get_factory):
actual: HelpProcessor = get_factory.get_processor([None, "help"])
for p in actual:
p.process()
2 changes: 1 addition & 1 deletion zero_to_one_hundred/tests/test_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_write(get_config_map, persist_fs, process_fs, http_url, http_url_2):
actual = Map(get_config_map, persist_fs, sections=sections)


def test_asMarkDown(get_config_map,persist_fs, process_fs, http_url, http_url_2):
def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url, http_url_2):
sections: List[Section] = [
Section(get_config_map, persist_fs, process_fs, http_url, False),
Section(get_config_map, persist_fs, process_fs, http_url_2, False),
Expand Down
4 changes: 1 addition & 3 deletions zero_to_one_hundred/tests_sb/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,4 @@ def get_factory_provider(env_map_yaml):

@pytest.fixture
def get_factory(env_map_yaml, persist_fs, process_fs):
return SBFactory(
env_map_yaml, persist_fs, process_fs
)
return SBFactory(env_map_yaml, persist_fs, process_fs)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

@patch("zero_to_one_hundred.factories.sb_factory.SBFactory.get_processor")
def test_process(get_factory, http_url):
actual: SnatchBookProcessor = get_factory.get_processor([None, "snatch_book", http_url])
actual: SnatchBookProcessor = get_factory.get_processor(
[None, "snatch_book", http_url]
)
for p in actual:
try:
p.process()
Expand Down
4 changes: 3 additions & 1 deletion zero_to_one_hundred/tests_sb/test_refresh_toc_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

@patch("zero_to_one_hundred.factories.sb_factory.SBFactory.get_processor")
def test_process(get_factory_provider):
actual: RefreshTocProcessor = get_factory_provider.get_processor([None, "refresh_toc"])
actual: RefreshTocProcessor = get_factory_provider.get_processor(
[None, "refresh_toc"]
)
for p in actual:
p.process()
7 changes: 1 addition & 6 deletions zero_to_one_hundred/tests_sb/test_sb_factory_provider.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider


# pylint: disable=W0621


def test_pass(
get_config_map,
persist_fs,
process_fs,get_factory
):
def test_pass(get_config_map, persist_fs, process_fs, get_factory):
actual = SBFactoryProvider(persist_fs, process_fs)
assert isinstance(actual.provide(), type(get_factory))
4 changes: 2 additions & 2 deletions zero_to_one_hundred/tests_sb/test_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url, http_url2)
# TOC
## `0` books
### 2099/01/01 - 00:00:00
| ISBN | | | | `json-contents` | `status` |
| ISBN | img | epub | pdf | `json-contents` | `status` |
|--- |--- |--- |--- |--- |--- |
"""
assert str_relaxed(current) == str_relaxed(expected)
assert str_relaxed("".join(current)) == str_relaxed("".join(expected))
7 changes: 0 additions & 7 deletions zero_to_one_hundred/views/markdown_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,3 @@ class MarkdownRenderer(ABC):
@abstractmethod
def asMarkDown(self) -> str:
pass

@staticmethod
def render_path_local(raw_path, root_path):
"""
use relative path and convert " " to %20
"""
return raw_path.replace(root_path, "./").replace(" ", "%20")

0 comments on commit 520d013

Please sign in to comment.