Skip to content

Commit

Permalink
114 add new sort as last opened (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
obar1 authored Aug 20, 2024
1 parent 2594cc0 commit f9e08ef
Show file tree
Hide file tree
Showing 68 changed files with 520 additions and 408 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- uses: actions/checkout@v3
- name: install packages
run: make install
- name: format
run: make format
- name: refactor
run: make refactor
- name: test
run: make test
- name: testint
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ safaribooks/
build
/dist
*.egg-info
pip-wheel-metadata/


# logs
logs/
8 changes: 4 additions & 4 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ function setup {
function setup0to100 {
rm -rf 0to100/

cp ./zero_to_one_hundred/tests/resources/gcp_map.yaml map.yaml
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_sb/resources/map.yaml .
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
Expand Down Expand Up @@ -50,12 +50,12 @@ function 0to100_sb {
setup0to100_sb

./main_sb.py help

./main_sb.py 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_sb.py 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
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ pylint>=2.17.5
pytest-cov>=4.0.0
pytest>=7.4.0
pytest-watch>=4.2.0
types-PyYAML>=6.0.12.12
types-PyYAML>=6.0.12.12
pyfakefs>=5.6.0
37 changes: 0 additions & 37 deletions runner.py

This file was deleted.

6 changes: 4 additions & 2 deletions zero_to_one_hundred/configs/a_config_map.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# pylint: disable=W0246
import os
from abc import ABC
from enum import Enum
import os

from zero_to_one_hundred.exceptions.errors import SomeError
from zero_to_one_hundred.repository.a_persist_fs import APersistFS


Expand All @@ -15,7 +16,8 @@ class SUPPORTED_EXTRA_MAP(Enum):

def __init__(self, persist_fs: APersistFS):
self.map_yaml_path = os.getenv(AConfigMap.MAP_YAML_PATH)
assert self.map_yaml_path is not None
if self.map_yaml_path is None:
raise SomeError(f"map_yaml_path {self.map_yaml_path} is not valid")
self.persist_fs = persist_fs

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion zero_to_one_hundred/configs/ztoh_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_repo_map_md(self):

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

@property
def get_repo_legend_type(self) -> str | None:
Expand Down
8 changes: 5 additions & 3 deletions zero_to_one_hundred/exceptions/errors.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
class NotURLFormatError(Exception):
def __init__(self, message):
# Call the base class constructor with the parameters it needs
super().__init__(message)


class UnsupportedConfigMapError(Exception):
def __init__(self, message):
# Call the base class constructor with the parameters it needs
super().__init__(message)


class UnsupportedOptionError(Exception):
def __init__(self, message):
# Call the base class constructor with the parameters it needs
super().__init__(message)


class SomeError(Exception):
def __init__(self, message):
super().__init__(message)
4 changes: 2 additions & 2 deletions zero_to_one_hundred/factories/a_factory_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod

from zero_to_one_hundred.repository.a_persist_fs import APersistFS
from zero_to_one_hundred.factories.a_factory import AFactory
from zero_to_one_hundred.repository.a_persist_fs import APersistFS


class AFactoryProvider(ABC):
Expand All @@ -12,5 +12,5 @@ def __init__(self, persist_fs: APersistFS, process_fs):
pass

@abstractmethod
def provide(self) -> AFactory:
def provide(self) -> None | AFactory:
pass
4 changes: 2 additions & 2 deletions zero_to_one_hundred/factories/sb_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from zero_to_one_hundred.configs.sb_config_map import SBConfigMap
from zero_to_one_hundred.factories.a_factory import AFactory
from zero_to_one_hundred.processors.help_processor import HelpProcessor
from zero_to_one_hundred.processors.refresh_toc_processor import RefreshTocProcessor
from zero_to_one_hundred.processors.snatch_book_processor import (
SnatchBookProcessor,
)
from zero_to_one_hundred.processors.help_processor import HelpProcessor
from zero_to_one_hundred.processors.refresh_toc_processor import RefreshTocProcessor
from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS
from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS

Expand Down
6 changes: 2 additions & 4 deletions zero_to_one_hundred/factories/sb_factory_provider.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS

from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS

from zero_to_one_hundred.configs.sb_config_map import SAFARI_BOOKS_MAP, SBConfigMap
from zero_to_one_hundred.exceptions.errors import UnsupportedConfigMapError
from zero_to_one_hundred.factories.a_factory_provider import AFactoryProvider
from zero_to_one_hundred.factories.sb_factory import SBFactory
from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS
from zero_to_one_hundred.repository.sb_process_fs import SBProcessFS


class SBFactoryProvider(AFactoryProvider):
Expand Down
6 changes: 2 additions & 4 deletions zero_to_one_hundred/factories/ztoh_factory.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from enum import Enum

from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS

from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS

from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.factories.a_factory import AFactory
from zero_to_one_hundred.processors.create_section_processor import (
Expand All @@ -13,6 +9,8 @@
from zero_to_one_hundred.processors.help_processor import HelpProcessor
from zero_to_one_hundred.processors.refresh_links_processor import RefreshLinksProcessor
from zero_to_one_hundred.processors.refresh_map_processor import RefreshMapProcessor
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS


class ZTOHFactory(AFactory):
Expand Down
6 changes: 3 additions & 3 deletions zero_to_one_hundred/factories/ztoh_factory_provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS
from zero_to_one_hundred.configs.ztoh_config_map import ZTOH_MAP, ZTOHConfigMap
from zero_to_one_hundred.factories.a_factory_provider import AFactoryProvider
from zero_to_one_hundred.factories.ztoh_factory import ZTOHFactory
from zero_to_one_hundred.configs.ztoh_config_map import ZTOH_MAP, ZTOHConfigMap
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS


class ZTOHFactoryProvider(AFactoryProvider):
Expand Down
20 changes: 12 additions & 8 deletions zero_to_one_hundred/models/map.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List
from zero_to_one_hundred.configs.a_config_map import AConfigMap
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS

from zero_to_one_hundred.configs.a_config_map import AConfigMap
from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.models.section import Section
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.views.markdown_renderer import MarkdownRenderer


Expand All @@ -25,6 +25,14 @@ def __init__(
def __repr__(self):
return f"Map {str(self.sections)}"

def get_sections(self):

if self.config_map.get_repo_sorted == "abc":
return sorted(self.sections, key=str)
if self.config_map.get_repo_sorted == "00:00:00":
return sorted(self.sections, key=lambda s: s.get_readme_md_time())
return self.sections

def asMarkDown(self) -> str:
lf_char = "\n"

Expand Down Expand Up @@ -59,17 +67,13 @@ def get_legend_as_md(self):

txt = f"""{f"# map {self.readme_md}, {len(self.sections)}"}
{f"## sorted: {self.config_map.get_repo_sorted}"}
{get_legend_as_md(self)}
{lf_char.join((section.asMarkDown() for section in self.sections))}
{lf_char.join((section.asMarkDown() for section in self.get_sections()))}
"""
return txt.replace(" ", "")

def write(self, as_sorted: bool):
# init with list of sections found
txt = self.asMarkDown()
def write(self, txt: str):
return self.persist_fs.write_file(self.readme_md, txt)

@classmethod
Expand Down
1 change: 0 additions & 1 deletion zero_to_one_hundred/models/meta_book.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re


from zero_to_one_hundred.configs.sb_config_map import SBConfigMap
from zero_to_one_hundred.models.metadata import Metadata
from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS
Expand Down
7 changes: 4 additions & 3 deletions zero_to_one_hundred/models/readme_md.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS

from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS

from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.views.markdown_renderer import MarkdownRenderer


Expand Down Expand Up @@ -41,3 +39,6 @@ def read(self):
data = self.persist_fs.read_file(self.readme_md)
lines = "FIXME:" if data is None else data
return lines

def get_latest_ts(self):
pass
23 changes: 12 additions & 11 deletions zero_to_one_hundred/models/section.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable= R0904

from zero_to_one_hundred.configs.a_config_map import AConfigMap
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.models.readme_md import ReadMeMD
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS
from zero_to_one_hundred.validator.validator import Validator
from zero_to_one_hundred.views.markdown_renderer import MarkdownRenderer

Expand Down Expand Up @@ -33,11 +33,10 @@ def __init__(
self.dir_readme_md = (
config_map.get_repo_path + "/" + self.dir_name + "/readme.md"
)

self.is_done = is_done

def __repr__(self):
return f"Section {self.http_url} {self.dir_readme_md } {self.is_done } {self.dir_name }"
return f"Section {self.http_url} {self.dir_readme_md} {self.is_done} {self.dir_name}"

def asMarkDown(self):
return (
Expand Down Expand Up @@ -78,16 +77,19 @@ def from_http_url_to_dir(cls, http_url):
.replace("\\", "§")
)

def write(self):
return self.persist_fs.make_dirs(
self.config_map.get_repo_path + "/" + self.dir_name
)
def write(self, txt: str):
return self.persist_fs.make_dirs(txt)

def write_done_section(self):
return self.persist_fs.done_section(
self.config_map.get_repo_path + "/" + self.dir_name
)

def get_readme_md_time(self):
return self.persist_fs.get_biz_ts(
self.config_map.get_repo_path + "/" + self.dir_name
)

@classmethod
def from_http_url_to_dir_to(cls, dir_name):
return dir_name.replace("§", "/").replace("https///", "https://")
Expand Down Expand Up @@ -119,8 +121,7 @@ def is_valid_dir(cls, curr_dir: str):

def refresh_links(self):
def convert(line):
"""convert to [https://](https:§§§...readme) or leave as it is
1 level only -assert"""
"""convert to [https://](https:§§§...readme) or leave as it is"""
res = line
if str(line).strip("\n").startswith("https://"):
res = (
Expand Down Expand Up @@ -249,7 +250,7 @@ def __eq__(self, other):
return NotImplemented

return (
other.http_url == self.http_url
other.http_oreilly_1 == self.http_url
and other.dir_name == self.dir_name
and other.dir_readme_md == self.dir_readme_md
and other.is_done == self.is_done
Expand Down
1 change: 0 additions & 1 deletion zero_to_one_hundred/models/toc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List


from zero_to_one_hundred.configs.sb_config_map import SBConfigMap
from zero_to_one_hundred.models.meta_book import MetaBook
from zero_to_one_hundred.repository.sb_persist_fs import SBPersistFS
Expand Down
9 changes: 4 additions & 5 deletions zero_to_one_hundred/processors/create_section_processor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS

from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS

from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap
from zero_to_one_hundred.models.readme_md import ReadMeMD
from zero_to_one_hundred.models.section import Section
from zero_to_one_hundred.processors.a_processor import AProcessor
from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS
from zero_to_one_hundred.repository.ztoh_process_fs import ZTOHProcessFS
from zero_to_one_hundred.validator.validator import Validator


Expand Down Expand Up @@ -39,7 +37,8 @@ def process(self):
self.http_url,
is_done=False,
)
section.write()
txt = self.config_map.get_repo_path + "/" + section.dir_name
section.write(txt)
readme_md: ReadMeMD = ReadMeMD(
self.config_map,
self.persist_fs,
Expand Down
Loading

0 comments on commit f9e08ef

Please sign in to comment.