diff --git a/.gitignore b/.gitignore index e8d6f9a..1cebb58 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ venv/ # test related 0to100**/ 978*/ +0*/ map.md repo/ toc*.md diff --git a/Makefile b/Makefile index d669bed..41f2a35 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ test: python -m pytest zero_to_one_hundred testint: - bash demo.sh 0to100 && bash demo.sh 0to100_sb + bash demo.sh 0to100_zt && bash demo.sh 0to100_sb format: black zero_to_one_hundred diff --git a/README.md b/README.md index f35f13d..288e0d4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Given a 'url', it creates the entry in a markdown map and a folder and links the just open this repo in your GitHub Codespace and run the demo as: ```bash -bash demo.sh 0to100 +bash demo.sh 0to100_zt ``` ![](termtosvg_0oihyn7a.svg) @@ -79,7 +79,7 @@ export MAP_YAML_PATH=map.yaml ```bash chmod +x *.py -./main.py help +./main.py zt help ``` ![](50a86373-910b-4a12-85ef-251b6d4f08f0.png) @@ -90,10 +90,10 @@ chmod +x *.py ```bash url=https://cloud.google.com/docs -./main.py create_section $url +./main.py zt create_section $url url=https://cloud.google.com/help -./main.py create_section $url +./main.py zt create_section $url #...etc ``` @@ -152,7 +152,7 @@ vim map.yaml ```bash chmod +x *.py -./main_sb.py help +./main.py sb help ``` ![](63fd79b5-ad41-45fd-a2dc-367f317bcc0c.png) @@ -163,7 +163,7 @@ chmod +x *.py ```bash url=https://learning.oreilly.com/library/view/hunt-the-pragmatic-programmer/020161622X/ -./main_sb.py snatch_book $url +./main.py sb snatch_book $url ``` and you have a `toc.md` for free to use as your index (bookmark it) diff --git a/demo.sh b/demo.sh index 6c78841..a1d7d56 100644 --- a/demo.sh +++ b/demo.sh @@ -5,21 +5,15 @@ function setup { # set -x export MAP_YAML_PATH=map.yaml - rm -rf safaribooks/ - pip install . chmod +x main*.py } -function setup0to100 { - rm -rf 0to100/ - +function setup0to100_zt { cp ./zero_to_one_hundred/tests/test_ztoh/resources/gcp_map.yaml map.yaml } function setup0to100_sb { - rm -rf 978*/ - cp ./zero_to_one_hundred/tests/tests_sb/resources/map.yaml map.yaml # safari books from lorenzodifuccia @@ -27,12 +21,13 @@ function setup0to100_sb { pip install --quiet -r safaribooks/requirements.txt } -function 0to100 { +function 0to100_zt { # 0to100 - setup0to100 + setup0to100_zt - ./main.py help + ./main.py zt help content=$(cat << 'EOF' +https://www.cloudskillsboost.google/0 https://www.cloudskillsboost.google/paths/16 https://www.cloudskillsboost.google/games/4424/labs/28651 https://www.cloudskillsboost.google/course_templates/3 @@ -42,9 +37,12 @@ https://storage.googleapis.com/cloud-training/cls-html5-courses/T-BQRS-I/M1/inde EOF ) while IFS= read -r section || [[ -n "$section" ]]; do - ./main.py create_section "$section" + ./main.py zt create_section "$section" done <<< "$content" +echo "# a_custom_header 0" >> 0to100/https§§§www.cloudskillsboost.google§0/readme.md + +./main.py zt done_section "https://www.cloudskillsboost.google/0" ls -1R 0to100 cp toc.md toc_0to100.md @@ -54,17 +52,17 @@ function 0to100_sb { # 0to100 safari books setup0to100_sb - ./main_sb.py help + ./main.py sb help - ./main_sb.py snatch_book https://learning.oreilly.com/course/clean-code-fundamentals/9780134661742 + ./main.py sb snatch_book https://learning.oreilly.com/course/clean-code-fundamentals/9780134661742 echo 'add any metadata you like' echo '{"title": "Clean Code Fundamentals"}'> 9780134661742/9780134661742.json - ./main_sb.py refresh_toc + ./main.py sb refresh_toc - ./main_sb.py snatch_book https://learning.oreilly.com/library/view/rewire-your-brain/9781119895947 + ./main.py sb snatch_book https://learning.oreilly.com/library/view/rewire-your-brain/9781119895947 echo 'pretend book was read fully and get % calc for free :P' echo '{"page_curr": "100", "page_tot": "100", "url":"https://www.oreilly.com/library/view/rewire-your-brain/9781119895947"}' > 9781119895947/9781119895947.json - ./main_sb.py refresh_toc + ./main.py sb refresh_toc ls -1R 978* cp toc.md toc_0to100_sb.md diff --git a/main.py b/main.py index 855e669..9b327a3 100755 --- a/main.py +++ b/main.py @@ -2,14 +2,30 @@ # coding: utf-8 import sys +import logging -from zero_to_one_hundred.factories.ztoh_factory_provider import ZTOHFactoryProvider -from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS as persist_fs -from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS as process_fs from zero_to_one_hundred.runner import run_core -import logging -logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') if __name__ == "__main__": - run_core(sys.argv, ZTOHFactoryProvider(persist_fs, process_fs)) + logger = logging.getLogger(__name__) + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + + err_msg = f'zt or sb available, passed {str(sys.argv)}' + try: + arg1= sys.argv[1] + match arg1: + case 'zt': + from zero_to_one_hundred.factories.ztoh_factory_provider import ZTOHFactoryProvider + from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS as persist_fs + from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS as process_fs + run_core(sys.argv, ZTOHFactoryProvider(persist_fs, process_fs)) + case 'sb': + from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider + from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS as persist_fs + from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS as process_fs + run_core(sys.argv, SBFactoryProvider(persist_fs, process_fs)) + case _: + raise ValueError(err_msg) + except Exception as e: + logging.info(err_msg) + diff --git a/main_sb.py b/main_sb.py deleted file mode 100755 index bd24256..0000000 --- a/main_sb.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python3 -# coding: utf-8 -import logging -import sys -from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider -from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS as persist_fs -from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS as process_fs -from zero_to_one_hundred.runner import run_core -logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') -if __name__ == "__main__": - run_core(sys.argv, SBFactoryProvider(persist_fs, process_fs)) diff --git a/zero_to_one_hundred/configs/a_config_map.py b/zero_to_one_hundred/configs/a_config_map.py index aae0321..bdd47d9 100644 --- a/zero_to_one_hundred/configs/a_config_map.py +++ b/zero_to_one_hundred/configs/a_config_map.py @@ -20,7 +20,7 @@ def __init__(self, persist_fs: APersistFS): self.map_yaml_path = os.getenv(AConfigMap.MAP_YAML_PATH) if self.map_yaml_path is None: raise SomeError( - f"map_yaml_path {self.map_yaml_path} is not valid, please set it in the env" + f"map_yaml_path {self.map_yaml_path} is not valid,\nplease set it in the env ex:\n`export MAP_YAML_PATH=map.yaml`" ) self.persist_fs = persist_fs diff --git a/zero_to_one_hundred/factories/sb_factory.py b/zero_to_one_hundred/factories/sb_factory.py index 2488f79..82fe63d 100644 --- a/zero_to_one_hundred/factories/sb_factory.py +++ b/zero_to_one_hundred/factories/sb_factory.py @@ -38,7 +38,7 @@ def get_processor(self, args): ) parser.add_argument("p1", type=str, help="arg p1", nargs="?", default=None) - args = parser.parse_args(args[1:]) + args = parser.parse_args(args[2:]) cmd = args.cmd p1 = args.p1 if cmd == SBFactory.SUPPORTED_PROCESSOR.snatch_book.name: diff --git a/zero_to_one_hundred/factories/ztoh_factory.py b/zero_to_one_hundred/factories/ztoh_factory.py index d419978..e594496 100644 --- a/zero_to_one_hundred/factories/ztoh_factory.py +++ b/zero_to_one_hundred/factories/ztoh_factory.py @@ -45,7 +45,7 @@ def get_processor(self, args): ) parser.add_argument("p1", type=str, help="arg p1", nargs="?", default=None) - args = parser.parse_args(args[1:]) + args = parser.parse_args(args[2:]) cmd = args.cmd p1 = args.p1 diff --git a/zero_to_one_hundred/models/map.py b/zero_to_one_hundred/models/map.py index 252d72d..07eb9f1 100644 --- a/zero_to_one_hundred/models/map.py +++ b/zero_to_one_hundred/models/map.py @@ -39,8 +39,7 @@ def as_mark_down(self) -> str: lf_char = "\n" def get_legend_as_md(self): - txt: str = """ - ## legend: + txt: str = """## legend: """ txt += lf_char txt += self.config_map.get_legend_icons_as_md diff --git a/zero_to_one_hundred/models/section.py b/zero_to_one_hundred/models/section.py index 2363065..224fc57 100644 --- a/zero_to_one_hundred/models/section.py +++ b/zero_to_one_hundred/models/section.py @@ -55,7 +55,7 @@ def get_http_url(self): @property def get_done_as_md(self): - return "`done`" if self.is_done else "`wip`" + return " `done` " if self.is_done else " `wip` " @property def get_dir_name(self): diff --git a/zero_to_one_hundred/repository/ztoh_persist_fs.py b/zero_to_one_hundred/repository/ztoh_persist_fs.py index 7e5660e..d6f0b19 100644 --- a/zero_to_one_hundred/repository/ztoh_persist_fs.py +++ b/zero_to_one_hundred/repository/ztoh_persist_fs.py @@ -28,19 +28,16 @@ def done_section_status(cls, abs_repo_path, path): path = abs_repo_path + os.sep + path + os.sep + ".done" logging.info(f"path {path}") exists = os.path.exists(path) - logging.info(f"exists {exists}") if exists: return True return False @classmethod def get_biz_ts(cls, path): - # logging.info(f"path {path}") + logging.info(f"path {path}") exists = os.path.exists(path) - # logging.info(f"exists {exists}") if exists: res = os.path.getmtime(path) - # logging.info(f"time {path} {res}") return res return time.time() diff --git a/zero_to_one_hundred/tests/test_ztoh/test_help_processor.py b/zero_to_one_hundred/tests/test_ztoh/test_help_processor.py index dadfab3..3e36689 100644 --- a/zero_to_one_hundred/tests/test_ztoh/test_help_processor.py +++ b/zero_to_one_hundred/tests/test_ztoh/test_help_processor.py @@ -2,6 +2,6 @@ def test_process(get_factory): - actual: HelpProcessor = get_factory.get_processor([None, "help"]) + actual: HelpProcessor = get_factory.get_processor([None, None, "help"]) for p in actual: p.process() diff --git a/zero_to_one_hundred/tests/tests_sb/resources/map.yaml b/zero_to_one_hundred/tests/tests_sb/resources/map.yaml index 1cdbea3..dd45669 100644 --- a/zero_to_one_hundred/tests/tests_sb/resources/map.yaml +++ b/zero_to_one_hundred/tests/tests_sb/resources/map.yaml @@ -2,7 +2,7 @@ type: safari-books-map configs: download_engine_path: "safaribooks/safaribooks.py" download_engine_books_path: "safaribooks/Books" - download_books: true + download_books: false oreilly_username: "username" oreilly_userpassword: "userpassword" split_pdf_pages: 100 diff --git a/zero_to_one_hundred/tests/tests_sb/test_sb_config_map.py b/zero_to_one_hundred/tests/tests_sb/test_sb_config_map.py index 8591c17..5cfc915 100644 --- a/zero_to_one_hundred/tests/tests_sb/test_sb_config_map.py +++ b/zero_to_one_hundred/tests/tests_sb/test_sb_config_map.py @@ -13,7 +13,7 @@ def test_provide__pass(get_config_map: SBConfigMap): assert actual.get_oreilly_userpassword is not None assert actual.get_oreilly_userpassword is not None assert actual.get_split_pdf_pages == 100 - assert actual.get_download_books is True + assert actual.get_download_books is False def test__repr__(get_config_map: SBConfigMap, get_map_yaml_path: str):