Skip to content

Commit

Permalink
merge main and main_sb py (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
obar1 authored Sep 11, 2024
1 parent 75adf89 commit 241cd37
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ venv/
# test related
0to100**/
978*/
0*/
map.md
repo/
toc*.md
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
```

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 14 additions & 16 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@ 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
git clone https://github.com/lorenzodifuccia/safaribooks.git
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
Expand All @@ -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
Expand All @@ -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
Expand Down
30 changes: 23 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

12 changes: 0 additions & 12 deletions main_sb.py

This file was deleted.

2 changes: 1 addition & 1 deletion zero_to_one_hundred/configs/a_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion zero_to_one_hundred/factories/sb_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion zero_to_one_hundred/factories/ztoh_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions zero_to_one_hundred/models/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zero_to_one_hundred/models/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 1 addition & 4 deletions zero_to_one_hundred/repository/ztoh_persist_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion zero_to_one_hundred/tests/test_ztoh/test_help_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion zero_to_one_hundred/tests/tests_sb/resources/map.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zero_to_one_hundred/tests/tests_sb/test_sb_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 241cd37

Please sign in to comment.