Skip to content

Commit 9b6f3e0

Browse files
authored
125 yaml sb and zt semplification (#126)
1 parent 202301e commit 9b6f3e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+109
-110
lines changed

.gitignore

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ venv/
1717
# demo
1818
0to100**/
1919
978*/
20-
0*/
21-
repo/
2220
safaribooks/
23-
*.yaml
24-
toc.md
2521

2622
# pip install
2723
build
2824
/dist
2925
*.egg-info
3026
pip-wheel-metadata/
3127

32-
3328
# logs
34-
logs/
29+
logs/
30+
31+
# daily use
32+
map.yaml
33+
toc.md

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
.PHONY: install test testint format lint refactor pr
2+
13
install:
24
pip install --upgrade pip && pip install -r requirements-dev.txt
35

46
test:
57
python -m pytest zero_to_one_hundred
68

79
testint:
8-
bash demo.sh zt && bash demo.sh sb
10+
bash demo.sh zo && bash demo.sh sb
911

1012
format:
1113
black zero_to_one_hundred

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Given a 'url', it creates the entry in a markdown map and a folder and links the
1616
just open this repo in your GitHub Codespace and run the demo as:
1717

1818
```bash
19-
bash demo.sh zt
20-
```
19+
bash demo.sh zo
20+
```
2121

2222
![](2dc4491c-fa27-4c5e-bd0c-71951b3ef0e5.png)
23-
[here](./toc_zt.md)
23+
[here](./toc_zo.md)
2424

2525
```bash
2626
bash demo.sh sb
@@ -39,17 +39,17 @@ commands:
3939
```
4040
create_section = create a new section
4141
section=https://www.cloudskillsboost.google/paths/16
42-
./main.py zt create_section "$section"
42+
./main.py zo create_section "$section"
4343
4444
done_section = tag a section as done
4545
section=https://www.cloudskillsboost.google/paths/16
46-
./main.py zt done_section "$section"
46+
./main.py zo done_section "$section"
4747
4848
refresh_map = refresh the section map
49-
./main.py zt refresh_map
49+
./main.py zo refresh_map
5050
5151
refresh_links = refresh links to sections in the readme.md(s)
52-
./main.py zt refresh_links
52+
./main.py zo refresh_links
5353
```
5454

5555
> tip
@@ -88,7 +88,7 @@ export MAP_YAML_PATH=map.yaml
8888

8989
chmod +x *.py
9090
# run main
91-
./main.py zt help
91+
./main.py zo help
9292
```
9393

9494

@@ -176,7 +176,7 @@ and you have a `toc.md` for free to use as your index (bookmark it)
176176

177177
## online example
178178

179-
- zt
179+
- zo
180180

181181
https://github.com/obar1/zero2hero
182182

demo.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function setup {
99

1010
chmod +x main.py
1111
}
12-
function setup_zt {
13-
cp ./zero_to_one_hundred/tests/test_ztoh/resources/gcp_map.yaml map.yaml
12+
function setup_zo {
13+
cp ./zero_to_one_hundred/tests/tests_zo/resources/gcp_map.yaml map.yaml
1414
}
1515

1616
function setup_sb {
@@ -21,11 +21,11 @@ function setup_sb {
2121
pip install --quiet -r safaribooks/requirements.txt
2222
}
2323

24-
function zt {
24+
function zo {
2525
# 0to100
26-
setup_zt
26+
setup_zo
2727

28-
./main.py zt help
28+
./main.py zo help
2929
content=$(
3030
cat <<'EOF'
3131
https://www.cloudskillsboost.google/0
@@ -37,15 +37,15 @@ https://storage.googleapis.com/cloud-training/cls-html5-courses/T-BQRS-I/M1/inde
3737
EOF
3838
)
3939
while IFS= read -r section || [[ -n "$section" ]]; do
40-
./main.py zt create_section "$section"
40+
./main.py zo create_section "$section"
4141
done <<<"$content"
4242

4343
echo "# a_custom_header 0" >>0to100/https§§§www.cloudskillsboost.google§0/readme.md
4444

45-
./main.py zt done_section "https://www.cloudskillsboost.google/0"
45+
./main.py zo done_section "https://www.cloudskillsboost.google/0"
4646

4747
ls -1R 0to100
48-
cp toc.md toc_zt.md
48+
cp toc.md toc_zo.md
4949
}
5050

5151
function sb {
@@ -72,7 +72,7 @@ function sb {
7272
#!/bin/bash
7373

7474
if [ $# -eq 0 ]; then
75-
echo "No arguments were passed: use sb or zt"
75+
echo "No arguments were passed: use sb or zo"
7676
else
7777
setup
7878
$1

main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/usr/bin/env python3
22
# coding: utf-8
33

4-
from enum import Enum
5-
import sys
64
import logging
5+
import sys
76

87
from zero_to_one_hundred.exceptions.errors import UnsupportedOptionError
98
from zero_to_one_hundred.runner import run_core
109
from zero_to_one_hundred.validator.validator import Validator
11-
10+
1211
if __name__ == "__main__":
1312
logger = logging.getLogger(__name__)
1413
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
1514
try:
16-
arg1= sys.argv[1]
17-
match arg1:
18-
case 'zt':
15+
args = sys.argv[1:]
16+
cmd , p1 , p2 = Validator.validate_args(args)
17+
match cmd:
18+
case 'zo':
1919
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS as persist_fs
2020
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS as process_fs
2121
from zero_to_one_hundred.factories.ztoh_factory_provider import ZTOHFactoryProvider
22-
run_core(sys.argv, ZTOHFactoryProvider(persist_fs, process_fs))
22+
run_core(args[1:], ZTOHFactoryProvider(persist_fs, process_fs))
2323
case 'sb':
2424
from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS as persist_fs
2525
from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS as process_fs
2626
from zero_to_one_hundred.factories.sb_factory_provider import SBFactoryProvider
27-
run_core(sys.argv, SBFactoryProvider(persist_fs, process_fs))
27+
run_core(args[1:], SBFactoryProvider(persist_fs, process_fs))
2828
case _:
2929
raise ValueError
30-
except (ValueError,IndexError, TypeError,UnsupportedOptionError):
30+
except (ValueError,IndexError, TypeError,UnsupportedOptionError) as e:
3131
from zero_to_one_hundred.repository.a_persist_fs import APersistFS as persist_fs
3232
from zero_to_one_hundred.factories.a_factory_provider import AFactoryProvider
3333
run_core(sys.argv, AFactoryProvider(persist_fs))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="0to100",
15-
version="0.5.3",
15+
version="0.5.4",
1616
author="obar1",
1717
packages=find_packages(),
1818
author_email="obar1+gh@pm.me",

toc_sb.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11

22
# TOC
33
## `2` metabook
4-
### 2024/09/13-11:06:37
4+
### 2024/09/15-16:52:50
55

66
## legend:
77

88
**legend_icons**
9-
`Book` :cyclone:
9+
`Book` :book:
10+
`Event` :floppy_disk:
11+
`Course` :whale:
1012

1113
| ISBN | img | `meta-contents` | `json-contents` | `status` | `icons`
1214
|--- |--- |--- |--- |--- |--- |
13-
|<span style="color:blue">**9780134661742**</span>|![`img`](./9780134661742/9780134661742.png)|[`xyz`](./9780134661742/)|{'isbn': '9780134661742',<br/> 'pages_perc': 'n/a',<br/> 'title': 'Clean Code Fundamentals',<br/> 'url': '> https://learning.oreilly.com/library/9780134661742 <'}|<span style="color:yellow">**WIP**</span>|:cyclone:|
14-
|<span style="color:blue">**9781119895947**</span>|![`img`](./9781119895947/9781119895947.png)|[`xyz`](./9781119895947/)|{'isbn': '9781119895947',<br/> 'page_curr': '100',<br/> 'page_tot': '100',<br/> 'pages_perc': '100.0%',<br/> 'url': '> https://www.oreilly.com/library/view/rewire-your-brain/9781119895947 <'}|<span style="color:green">**DONE**</span>|:cyclone:|
15+
|<span style="color:blue">**9780134661742**</span>|![`img`](./9780134661742/9780134661742.png)|[`xyz`](./9780134661742/)|{'isbn': '9780134661742',<br/> 'pages_perc': 'n/a',<br/> 'title': 'Clean Code Fundamentals',<br/> 'url': '> https://learning.oreilly.com/library/9780134661742 <'}|<span style="color:yellow">**WIP**</span>|:book:|
16+
|<span style="color:blue">**9781119895947**</span>|![`img`](./9781119895947/9781119895947.png)|[`xyz`](./9781119895947/)|{'isbn': '9781119895947',<br/> 'page_curr': '100',<br/> 'page_tot': '100',<br/> 'pages_perc': '100.0%',<br/> 'url': '> https://www.oreilly.com/library/view/rewire-your-brain/9781119895947 <'}|<span style="color:green">**DONE**</span>|:book:|
1517

toc_zt.md renamed to toc_zo.md

File renamed without changes.

zero_to_one_hundred/configs/sb_config_map.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ def get_books_path(self):
1717

1818
@property
1919
def get_download_engine_path(self):
20-
return self.load["configs"]["download_engine_path"]
20+
return self.load["download_engine_path"]
2121

2222
@property
2323
def get_download_engine_books_path(self):
24-
return self.load["configs"]["download_engine_books_path"]
24+
return self.load["download_engine_books_path"]
2525

2626
@property
2727
def get_oreilly_username(self):
28-
return self.load["configs"]["oreilly_username"]
28+
return self.load["oreilly_secrets"]["username"]
2929

3030
@property
3131
def get_oreilly_userpassword(self):
32-
return self.load["configs"]["oreilly_userpassword"]
32+
return self.load["oreilly_secrets"]["password"]
3333

3434
@property
3535
def get_split_pdf_pages(self):
36-
return int(self.load["configs"]["split_pdf_pages"])
36+
return int(self.load["split_pdf_pages"])
3737

3838
@property
3939
def get_download_books(self):
40-
return bool(self.load["configs"]["download_books"])
40+
return bool(self.load["download_books"])

zero_to_one_hundred/configs/ztoh_config_map.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from zero_to_one_hundred.configs.a_config_map import AConfigMap
22
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
33

4-
ZTOH_MAP = "ztoh-map"
4+
ZTOH_MAP = "zero-to-one-hundred-map"
55

66

77
class ZTOHConfigMap(AConfigMap):
@@ -14,8 +14,8 @@ def get_repo_path(self):
1414

1515
@property
1616
def get_repo_map_md(self):
17-
return self.load["repo"]["map_md"]
17+
return self.load["repo"]["idx_id"]
1818

1919
@property
2020
def get_repo_sorted(self) -> bool:
21-
return self.load["repo"].get("sorted")
21+
return self.load["repo"].get("idx_sort")

zero_to_one_hundred/factories/a_factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ class AFactory:
1111
"""AFactory class."""
1212

1313
class SUPPORTED_PROCESSOR(Enum):
14-
zt = 1
14+
zo = 1
1515
sb = 2
1616
help = 3
1717

1818
extended_help = """
19-
zt = zero to 100
20-
./main.py zt help
19+
zo = zero to 100
20+
./main.py zo help
2121
2222
sb = sb to 100
2323
./main.py sb help
@@ -29,7 +29,7 @@ class SUPPORTED_PROCESSOR(Enum):
2929
def __init__(self, persist_fs: APersistFS):
3030
self.persist_fs = persist_fs
3131

32-
def get_processor(self,args) -> Generator[AProcessor, None, None]:
32+
def get_processor(self, args) -> Generator[AProcessor, None, None]:
3333
yield self.help_processor()
3434

3535
def help_processor(self):

zero_to_one_hundred/factories/sb_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
self.process_fs = process_fs
3636

3737
def get_processor(self, args):
38-
cmd, p1 = Validator.validate_args(args)
38+
cmd, p1, _ = Validator.validate_args(args)
3939
if cmd == SBFactory.SUPPORTED_PROCESSOR.snatch_book.name:
4040
http_url = p1
4141
yield self.snatch_book_processor(http_url)

zero_to_one_hundred/factories/ztoh_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ class SUPPORTED_PROCESSOR(Enum):
2626
extended_help = """
2727
create_section = create a new section
2828
section=https://www.cloudskillsboost.google/paths/16
29-
./main.py zt create_section "$section"
29+
./main.py zo create_section "$section"
3030
3131
done_section = tag a section as done
3232
section=https://www.cloudskillsboost.google/paths/16
33-
./main.py zt done_section "$section"
33+
./main.py zo done_section "$section"
3434
3535
refresh_map = refresh the section map
36-
./main.py zt refresh_map
36+
./main.py zo refresh_map
3737
3838
refresh_links = refresh links to sections in the readme.md(s)
39-
./main.py zt refresh_links
39+
./main.py zo refresh_links
4040
"""
4141

4242
def __init__(
@@ -50,7 +50,7 @@ def __init__(
5050
self.process_fs = process_fs
5151

5252
def get_processor(self, args):
53-
cmd, p1 = Validator.validate_args(args)
53+
cmd, p1, _ = Validator.validate_args(args)
5454
if cmd == ZTOHFactory.SUPPORTED_PROCESSOR.create_section.name:
5555
yield self.create_section_processor(p1)
5656
yield self.refresh_map_processor()

zero_to_one_hundred/tests/test_ztoh/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

zero_to_one_hundred/tests/test_ztoh/resources/map.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

zero_to_one_hundred/tests/test_ztoh/resources/map_sorted_0.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

zero_to_one_hundred/tests/test_ztoh/resources/map_sorted_1.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

zero_to_one_hundred/tests/test_ztoh/resources/unsupported_map.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
type: safari-books-map
2-
configs:
3-
download_engine_path: "safaribooks/safaribooks.py"
4-
download_engine_books_path: "safaribooks/Books"
5-
download_books: false
6-
oreilly_username: "username"
7-
oreilly_userpassword: "userpassword"
8-
split_pdf_pages: 0
2+
download_engine_path: "safaribooks/safaribooks.py"
3+
download_engine_books_path: "safaribooks/Books"
4+
download_books: false
5+
split_pdf_pages: 0
6+
oreilly_secrets:
7+
username: "username"
8+
password: "userpassword"
99
legend:
10-
type: "sb"
1110
icons:
1211
- name: Book
13-
icon: ":cyclone:"
12+
icon: ":book:"
1413
regex: "978"
14+
- name: Event
15+
icon: ":floppy_disk:"
16+
regex: "event"
17+
- name: Course
18+
icon: ":whale:"
19+
regex: "course"

0 commit comments

Comments
 (0)