Skip to content

Commit

Permalink
125 yaml sb and zt semplification (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
obar1 authored Sep 15, 2024
1 parent 202301e commit 9b6f3e0
Show file tree
Hide file tree
Showing 44 changed files with 109 additions and 110 deletions.
11 changes: 5 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ venv/
# demo
0to100**/
978*/
0*/
repo/
safaribooks/
*.yaml
toc.md

# pip install
build
/dist
*.egg-info
pip-wheel-metadata/


# logs
logs/
logs/

# daily use
map.yaml
toc.md
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.PHONY: install test testint format lint refactor pr

install:
pip install --upgrade pip && pip install -r requirements-dev.txt

test:
python -m pytest zero_to_one_hundred

testint:
bash demo.sh zt && bash demo.sh sb
bash demo.sh zo && bash demo.sh sb

format:
black zero_to_one_hundred
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ 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 zt
```
bash demo.sh zo
```

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

```bash
bash demo.sh sb
Expand All @@ -39,17 +39,17 @@ commands:
```
create_section = create a new section
section=https://www.cloudskillsboost.google/paths/16
./main.py zt create_section "$section"
./main.py zo create_section "$section"
done_section = tag a section as done
section=https://www.cloudskillsboost.google/paths/16
./main.py zt done_section "$section"
./main.py zo done_section "$section"
refresh_map = refresh the section map
./main.py zt refresh_map
./main.py zo refresh_map
refresh_links = refresh links to sections in the readme.md(s)
./main.py zt refresh_links
./main.py zo refresh_links
```

> tip
Expand Down Expand Up @@ -88,7 +88,7 @@ export MAP_YAML_PATH=map.yaml

chmod +x *.py
# run main
./main.py zt help
./main.py zo help
```


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

## online example

- zt
- zo

https://github.com/obar1/zero2hero

Expand Down
18 changes: 9 additions & 9 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function setup {

chmod +x main.py
}
function setup_zt {
cp ./zero_to_one_hundred/tests/test_ztoh/resources/gcp_map.yaml map.yaml
function setup_zo {
cp ./zero_to_one_hundred/tests/tests_zo/resources/gcp_map.yaml map.yaml
}

function setup_sb {
Expand All @@ -21,11 +21,11 @@ function setup_sb {
pip install --quiet -r safaribooks/requirements.txt
}

function zt {
function zo {
# 0to100
setup_zt
setup_zo

./main.py zt help
./main.py zo help
content=$(
cat <<'EOF'
https://www.cloudskillsboost.google/0
Expand All @@ -37,15 +37,15 @@ 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 zt create_section "$section"
./main.py zo 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"
./main.py zo done_section "https://www.cloudskillsboost.google/0"

ls -1R 0to100
cp toc.md toc_zt.md
cp toc.md toc_zo.md
}

function sb {
Expand All @@ -72,7 +72,7 @@ function sb {
#!/bin/bash

if [ $# -eq 0 ]; then
echo "No arguments were passed: use sb or zt"
echo "No arguments were passed: use sb or zo"
else
setup
$1
Expand Down
18 changes: 9 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#!/usr/bin/env python3
# coding: utf-8

from enum import Enum
import sys
import logging
import sys

from zero_to_one_hundred.exceptions.errors import UnsupportedOptionError
from zero_to_one_hundred.runner import run_core
from zero_to_one_hundred.validator.validator import Validator

if __name__ == "__main__":
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
try:
arg1= sys.argv[1]
match arg1:
case 'zt':
args = sys.argv[1:]
cmd , p1 , p2 = Validator.validate_args(args)
match cmd:
case 'zo':
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.factories.ztoh_factory_provider import ZTOHFactoryProvider
run_core(sys.argv, ZTOHFactoryProvider(persist_fs, process_fs))
run_core(args[1:], ZTOHFactoryProvider(persist_fs, process_fs))
case 'sb':
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.factories.sb_factory_provider import SBFactoryProvider
run_core(sys.argv, SBFactoryProvider(persist_fs, process_fs))
run_core(args[1:], SBFactoryProvider(persist_fs, process_fs))
case _:
raise ValueError
except (ValueError,IndexError, TypeError,UnsupportedOptionError):
except (ValueError,IndexError, TypeError,UnsupportedOptionError) as e:
from zero_to_one_hundred.repository.a_persist_fs import APersistFS as persist_fs
from zero_to_one_hundred.factories.a_factory_provider import AFactoryProvider
run_core(sys.argv, AFactoryProvider(persist_fs))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="0to100",
version="0.5.3",
version="0.5.4",
author="obar1",
packages=find_packages(),
author_email="[email protected]",
Expand Down
10 changes: 6 additions & 4 deletions toc_sb.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

# TOC
## `2` metabook
### 2024/09/13-11:06:37
### 2024/09/15-16:52:50

## legend:

**legend_icons**
`Book` :cyclone:
`Book` :book:
`Event` :floppy_disk:
`Course` :whale:

| ISBN | img | `meta-contents` | `json-contents` | `status` | `icons`
|--- |--- |--- |--- |--- |--- |
|<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:|
|<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:|
|<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:|
|<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:|
File renamed without changes.
12 changes: 6 additions & 6 deletions zero_to_one_hundred/configs/sb_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ def get_books_path(self):

@property
def get_download_engine_path(self):
return self.load["configs"]["download_engine_path"]
return self.load["download_engine_path"]

@property
def get_download_engine_books_path(self):
return self.load["configs"]["download_engine_books_path"]
return self.load["download_engine_books_path"]

@property
def get_oreilly_username(self):
return self.load["configs"]["oreilly_username"]
return self.load["oreilly_secrets"]["username"]

@property
def get_oreilly_userpassword(self):
return self.load["configs"]["oreilly_userpassword"]
return self.load["oreilly_secrets"]["password"]

@property
def get_split_pdf_pages(self):
return int(self.load["configs"]["split_pdf_pages"])
return int(self.load["split_pdf_pages"])

@property
def get_download_books(self):
return bool(self.load["configs"]["download_books"])
return bool(self.load["download_books"])
6 changes: 3 additions & 3 deletions zero_to_one_hundred/configs/ztoh_config_map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from zero_to_one_hundred.configs.a_config_map import AConfigMap
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS

ZTOH_MAP = "ztoh-map"
ZTOH_MAP = "zero-to-one-hundred-map"


class ZTOHConfigMap(AConfigMap):
Expand All @@ -14,8 +14,8 @@ def get_repo_path(self):

@property
def get_repo_map_md(self):
return self.load["repo"]["map_md"]
return self.load["repo"]["idx_id"]

@property
def get_repo_sorted(self) -> bool:
return self.load["repo"].get("sorted")
return self.load["repo"].get("idx_sort")
8 changes: 4 additions & 4 deletions zero_to_one_hundred/factories/a_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class AFactory:
"""AFactory class."""

class SUPPORTED_PROCESSOR(Enum):
zt = 1
zo = 1
sb = 2
help = 3

extended_help = """
zt = zero to 100
./main.py zt help
zo = zero to 100
./main.py zo help
sb = sb to 100
./main.py sb help
Expand All @@ -29,7 +29,7 @@ class SUPPORTED_PROCESSOR(Enum):
def __init__(self, persist_fs: APersistFS):
self.persist_fs = persist_fs

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

def help_processor(self):
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 @@ -35,7 +35,7 @@ def __init__(
self.process_fs = process_fs

def get_processor(self, args):
cmd, p1 = Validator.validate_args(args)
cmd, p1, _ = Validator.validate_args(args)
if cmd == SBFactory.SUPPORTED_PROCESSOR.snatch_book.name:
http_url = p1
yield self.snatch_book_processor(http_url)
Expand Down
10 changes: 5 additions & 5 deletions zero_to_one_hundred/factories/ztoh_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ class SUPPORTED_PROCESSOR(Enum):
extended_help = """
create_section = create a new section
section=https://www.cloudskillsboost.google/paths/16
./main.py zt create_section "$section"
./main.py zo create_section "$section"
done_section = tag a section as done
section=https://www.cloudskillsboost.google/paths/16
./main.py zt done_section "$section"
./main.py zo done_section "$section"
refresh_map = refresh the section map
./main.py zt refresh_map
./main.py zo refresh_map
refresh_links = refresh links to sections in the readme.md(s)
./main.py zt refresh_links
./main.py zo refresh_links
"""

def __init__(
Expand All @@ -50,7 +50,7 @@ def __init__(
self.process_fs = process_fs

def get_processor(self, args):
cmd, p1 = Validator.validate_args(args)
cmd, p1, _ = Validator.validate_args(args)
if cmd == ZTOHFactory.SUPPORTED_PROCESSOR.create_section.name:
yield self.create_section_processor(p1)
yield self.refresh_map_processor()
Expand Down
1 change: 0 additions & 1 deletion zero_to_one_hundred/tests/test_ztoh/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions zero_to_one_hundred/tests/test_ztoh/resources/map.yaml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

23 changes: 14 additions & 9 deletions zero_to_one_hundred/tests/tests_sb/resources/map.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
type: safari-books-map
configs:
download_engine_path: "safaribooks/safaribooks.py"
download_engine_books_path: "safaribooks/Books"
download_books: false
oreilly_username: "username"
oreilly_userpassword: "userpassword"
split_pdf_pages: 0
download_engine_path: "safaribooks/safaribooks.py"
download_engine_books_path: "safaribooks/Books"
download_books: false
split_pdf_pages: 0
oreilly_secrets:
username: "username"
password: "userpassword"
legend:
type: "sb"
icons:
- name: Book
icon: ":cyclone:"
icon: ":book:"
regex: "978"
- name: Event
icon: ":floppy_disk:"
regex: "event"
- name: Course
icon: ":whale:"
regex: "course"
Loading

0 comments on commit 9b6f3e0

Please sign in to comment.