yklibpy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. yklibpy-0.1.0/.editorconfig +15 -0
  2. yklibpy-0.1.0/.gitignore +12 -0
  3. yklibpy-0.1.0/.prettierrc +9 -0
  4. yklibpy-0.1.0/.python-version +1 -0
  5. yklibpy-0.1.0/PKG-INFO +20 -0
  6. yklibpy-0.1.0/README.md +0 -0
  7. yklibpy-0.1.0/db.yaml +1 -0
  8. yklibpy-0.1.0/pyproject.toml +86 -0
  9. yklibpy-0.1.0/src/yklibpy/__init__.py +17 -0
  10. yklibpy-0.1.0/src/yklibpy/common/__init__.py +15 -0
  11. yklibpy-0.1.0/src/yklibpy/common/convert_yaml_strip_tags.py +102 -0
  12. yklibpy-0.1.0/src/yklibpy/common/env.py +109 -0
  13. yklibpy-0.1.0/src/yklibpy/common/info.py +24 -0
  14. yklibpy-0.1.0/src/yklibpy/common/util.py +419 -0
  15. yklibpy-0.1.0/src/yklibpy/db/__init__.py +27 -0
  16. yklibpy-0.1.0/src/yklibpy/db/db_base.py +6 -0
  17. yklibpy-0.1.0/src/yklibpy/db/db_yaml.py +61 -0
  18. yklibpy-0.1.0/src/yklibpy/htmlparser/__init__.py +37 -0
  19. yklibpy-0.1.0/src/yklibpy/htmlparser/amazon.py +3 -0
  20. yklibpy-0.1.0/src/yklibpy/htmlparser/amazonsavedcartscraper.py +106 -0
  21. yklibpy-0.1.0/src/yklibpy/htmlparser/app.py +101 -0
  22. yklibpy-0.1.0/src/yklibpy/htmlparser/ascraper.py +77 -0
  23. yklibpy-0.1.0/src/yklibpy/htmlparser/configprepare.py +29 -0
  24. yklibpy-0.1.0/src/yklibpy/htmlparser/fanzadoujinpurchasedscraper.py +80 -0
  25. yklibpy-0.1.0/src/yklibpy/htmlparser/fanzadoujinscraper.py +235 -0
  26. yklibpy-0.1.0/src/yklibpy/htmlparser/h3scraper.py +68 -0
  27. yklibpy-0.1.0/src/yklibpy/htmlparser/htmlop.py +107 -0
  28. yklibpy-0.1.0/src/yklibpy/htmlparser/kuscraper.py +68 -0
  29. yklibpy-0.1.0/src/yklibpy/htmlparser/preparex.py +152 -0
  30. yklibpy-0.1.0/src/yklibpy/htmlparser/progress.py +36 -0
  31. yklibpy-0.1.0/src/yklibpy/htmlparser/py.typed +0 -0
  32. yklibpy-0.1.0/src/yklibpy/htmlparser/scraper.py +181 -0
  33. yklibpy-0.1.0/src/yklibpy/htmlparser/udemyscraper.py +224 -0
  34. yklibpy-0.1.0/src/yklibpy/tomlop/__init__.py +17 -0
  35. yklibpy-0.1.0/src/yklibpy/tomlop/tomlop.py +374 -0
  36. yklibpy-0.1.0/uv.lock +1052 -0
@@ -0,0 +1,15 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ insert_final_newline = true
7
+ indent_style = space
8
+ indent_size = 2
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.py]
12
+ indent_size = 4
13
+
14
+ [*.md]
15
+ trim_trailing_whitespace = false
@@ -0,0 +1,12 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
11
+ *.code-workspace
12
+ output_*.yaml
@@ -0,0 +1,9 @@
1
+ {
2
+ "tabWidth": 2,
3
+ "useTabs": false,
4
+ "semi": false,
5
+ "singleQuote": true,
6
+ "trailingComma": "es5",
7
+ "printWidth": 100
8
+ }
9
+
@@ -0,0 +1 @@
1
+ 3.14
yklibpy-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: yklibpy
3
+ Version: 0.1.0
4
+ Summary: Utilty Library by ykominami
5
+ Project-URL: Homepage, https://github.com/ykominami/yklibpy
6
+ Project-URL: Repository, https://github.com/ykominami/yklibpy
7
+ Author: Yasuo Kominami
8
+ License-Expression: MIT
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
15
+ Requires-Python: >=3.14
16
+ Requires-Dist: bs4>=0.0.2
17
+ Requires-Dist: chardet>=5.2.0
18
+ Requires-Dist: html5lib>=1.1
19
+ Requires-Dist: pyyaml>=6.0.3
20
+ Requires-Dist: toml>=0.10.2
File without changes
yklibpy-0.1.0/db.yaml ADDED
@@ -0,0 +1 @@
1
+ ""
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "yklibpy"
3
+ version = "0.1.0"
4
+ description = "Utilty Library by ykominami"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Yasuo Kominami"}
8
+ ]
9
+ requires-python = ">=3.14"
10
+ dependencies = [
11
+ "bs4>=0.0.2",
12
+ "chardet>=5.2.0",
13
+ "html5lib>=1.1",
14
+ "pyyaml>=6.0.3",
15
+ "toml>=0.10.2",
16
+ ]
17
+ license = "MIT" # ライセンス
18
+ # 分類の情報
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: Implementation :: PyPy",
26
+ ]
27
+
28
+
29
+ [build-system]
30
+ # requires = ["uv_build>=0.9.13,<0.10.0"]
31
+ requires = ["hatchling"]
32
+ # build-backend = "uv_build"
33
+ build-backend = "hatchling.build"
34
+
35
+ [dependency-groups]
36
+ dev = [
37
+ "black>=25.11.0",
38
+ "build>=1.3.0",
39
+ "hatch>=1.16.1",
40
+ "mypy>=1.19.0",
41
+ "pytest>=9.0.1",
42
+ "pytest-cov>=7.0.0",
43
+ "ruff>=0.14.7",
44
+ "twine>=6.2.0",
45
+ ]
46
+
47
+ [project.urls]
48
+ Homepage = "https://github.com/ykominami/yklibpy"
49
+ Repository = "https://github.com/ykominami/yklibpy"
50
+
51
+ [project.scripts]
52
+ # yklibpy-tomlop = "yklibpy:tomlop.main"
53
+ tomlop-ymain = "htmlparser:ymain"
54
+ # yklibpy-main = "yklibpy:main"
55
+ yklibpy-xmain = "yklibpy:xmain"
56
+ yklibpy-ymain = "yklibpy:htmlparser.ymain"
57
+ yklibpy-app = "yklibpy:htmlparser.app.ymain"
58
+ yklibpy-tomlop = "yklibpy:tomlop.xmain"
59
+ yklibpy-zmain = "yklibpy:tomlop.zmain"
60
+ yklibpy-toml2yaml = "yklibpy:tomlop.toml2yaml"
61
+ yklibpy-yaml2toml = "yklibpy:tomlop.yaml2toml"
62
+ # yklibpy-serve = "yklibpy_diff:server.main
63
+ yklibpy-db_yaml = "yklibpy.db:db_yaml"
64
+
65
+ [tool.pytest.ini_options]
66
+ addopts = "-ra -q"
67
+ testpaths = ["tests"]
68
+
69
+ [tool.hatch.build.targets.wheel]
70
+ packages = ["src/yklibpy"]
71
+
72
+ [tool.black]
73
+ line-length = 88
74
+ target-version = ['py314']
75
+ include = '\.pyi?$'
76
+
77
+ [tool.ruff]
78
+ lint.select = ["E", "F", "I", "N"]
79
+ # line-length = 88
80
+ # line-length = 120
81
+ lint.ignore = ["E501"]
82
+ target-version = "py314"
83
+
84
+ [tool.mypy]
85
+ python_version = "3.14"
86
+ strict = true
@@ -0,0 +1,17 @@
1
+ # from .htmlparser import htmlparser
2
+ # from .common import common
3
+ # from .tomlop import tomlop
4
+ from .db import db_yaml
5
+
6
+ def dbyaml():
7
+ db_yaml()
8
+
9
+ def xmain() -> str:
10
+ print("11 Hello from yklibpy.xmain!")
11
+ return "12 Hello from yklibpy.xmain!"
12
+
13
+ def ymain() -> str:
14
+ print("21 Y Hello from yklibpy.ymain!")
15
+ return "22 Y Hello from yklibpy.ymain!"
16
+
17
+
@@ -0,0 +1,15 @@
1
+ from .env import Env
2
+ from .info import Info
3
+ from .util import Util
4
+
5
+ def xmain() -> str:
6
+ print("Hello from yklibpy!")
7
+ return "Hello from yklibpy!"
8
+
9
+ def ymain() -> str:
10
+ print("Y Hello from yklibpy!")
11
+ return "Y Hello from yklibpy!"
12
+
13
+
14
+ if __name__ == "__main__":
15
+ xmain()
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import argparse
5
+ from pathlib import Path
6
+ import yaml
7
+
8
+
9
+ # PyYAML が付ける / あるいは YAML 内に書かれている可能性のあるタグ表現
10
+ DYNAMIC_INLINE_TABLE_TAGS = {
11
+ "tag:yaml.org,2002:python/object/new:toml.decoder.DynamicInlineTableDict",
12
+ "!!python/object/new:toml.decoder.DynamicInlineTableDict", # 念のため
13
+ }
14
+
15
+
16
+ class TagStrippingSafeLoader(yaml.SafeLoader):
17
+ """
18
+ SafeLoader をベースにしつつ、特定の python/object/new タグだけ
19
+ 普通の dict に落とすための Loader。
20
+ """
21
+ pass
22
+
23
+
24
+ def _dynamic_inline_table_dict_constructor(loader: yaml.SafeLoader, node: yaml.Node):
25
+ # node が mapping の想定
26
+ mapping = loader.construct_mapping(node, deep=True)
27
+ # toml の DynamicInlineTableDict は dictitems キー配下に実体が入っていることが多い
28
+ if isinstance(mapping, dict) and "dictitems" in mapping and isinstance(mapping["dictitems"], dict):
29
+ return mapping["dictitems"]
30
+ return mapping
31
+
32
+
33
+ def _register_constructors():
34
+ # 代表的なタグ(tag:...形式)を登録
35
+ TagStrippingSafeLoader.add_constructor(
36
+ "tag:yaml.org,2002:python/object/new:toml.decoder.DynamicInlineTableDict",
37
+ _dynamic_inline_table_dict_constructor,
38
+ )
39
+
40
+ # YAML 内で !!python/object/new:... と書かれていた場合に備えて multi_constructor も登録
41
+ def _multi_python_object_new(loader: yaml.SafeLoader, tag_suffix: str, node: yaml.Node):
42
+ # tag_suffix は "toml.decoder.DynamicInlineTableDict" のような文字列になる
43
+ full = f"tag:yaml.org,2002:python/object/new:{tag_suffix}"
44
+ if full == "tag:yaml.org,2002:python/object/new:toml.decoder.DynamicInlineTableDict":
45
+ return _dynamic_inline_table_dict_constructor(loader, node)
46
+ # それ以外の python/object/new は安全のため許可しない(明示的に失敗させる)
47
+ raise yaml.constructor.ConstructorError(
48
+ None, None,
49
+ f"Unsupported python/object/new tag: {full} (refuse to construct). "
50
+ f"Please strip/convert this node explicitly.",
51
+ node.start_mark,
52
+ )
53
+
54
+ TagStrippingSafeLoader.add_multi_constructor(
55
+ "tag:yaml.org,2002:python/object/new:",
56
+ _multi_python_object_new,
57
+ )
58
+
59
+
60
+ def strip_tags_and_dump(input_path: Path, output_path: Path):
61
+ text = input_path.read_text(encoding="utf-8")
62
+
63
+ data = yaml.load(text, Loader=TagStrippingSafeLoader)
64
+
65
+ # タグ無しで人間が読みやすい YAML を出力
66
+ dumped = yaml.safe_dump(
67
+ data,
68
+ allow_unicode=True,
69
+ sort_keys=False,
70
+ default_flow_style=False,
71
+ )
72
+
73
+ output_path.write_text(dumped, encoding="utf-8")
74
+
75
+
76
+ def main():
77
+ _register_constructors()
78
+
79
+ parser = argparse.ArgumentParser(
80
+ description="Convert YAML containing python/object/new tags into plain tag-free YAML."
81
+ )
82
+ parser.add_argument("input", type=Path, help="Input YAML path (e.g. a.yaml)")
83
+ parser.add_argument(
84
+ "-o", "--output",
85
+ type=Path,
86
+ default=None,
87
+ help="Output YAML path (default: <input>.stripped.yaml)",
88
+ )
89
+ args = parser.parse_args()
90
+
91
+ in_path: Path = args.input
92
+ if args.output is None:
93
+ out_path = in_path.with_suffix(in_path.suffix + ".stripped.yaml")
94
+ else:
95
+ out_path = args.output
96
+
97
+ strip_tags_and_dump(in_path, out_path)
98
+ print(f"written: {out_path}")
99
+
100
+
101
+ if __name__ == "__main__":
102
+ main()
@@ -0,0 +1,109 @@
1
+ from pathlib import Path
2
+ from typing import List, Optional
3
+
4
+ import yaml
5
+
6
+
7
+ class Env:
8
+ def __init__(self, config_path: Path = None):
9
+ """Load configuration and initialize base path/mode settings.
10
+
11
+ Args:
12
+ config_path (Path | None): YAML containing ``base_path`` and pattern
13
+ associations. When ``None`` the environment starts empty.
14
+
15
+ Returns:
16
+ None
17
+ """
18
+ self.base_path = None
19
+ self.pattern = None
20
+ self.config = {}
21
+ self.assoc = {}
22
+ # print(f"config_path={config_path}")
23
+ if config_path is not None:
24
+ with open(config_path, "r", encoding="utf-8") as f:
25
+ self.assoc = yaml.load(f, Loader=yaml.FullLoader)
26
+ # print(list(self.assoc.keys()))
27
+ # list = self.assoc.keys()
28
+ # for key in list:
29
+ # print(f"key={key}")
30
+
31
+ base_path_array = self.assoc["base_path"]
32
+ self.base_path = self.make_path(base_path_array)
33
+
34
+ def make_path(self, path_array: list[str]) -> Path | None:
35
+ """Convert a sequence of path components into a concrete path.
36
+
37
+ Args:
38
+ path_array (list[str]): Ordered segments such as
39
+ ``['C:/data', 'courses']``.
40
+
41
+ Returns:
42
+ Path | None: Composed path or ``None`` when no components exist.
43
+ """
44
+ base_path = None
45
+ if path_array is not None:
46
+ top_dir = path_array.pop(0)
47
+ top_path = Path(top_dir)
48
+ base_path = top_path / Path(*path_array)
49
+
50
+ return base_path
51
+
52
+ def mode(self):
53
+ """Return the scraper mode stored in the active pattern.
54
+
55
+ Returns:
56
+ str: Mode string, defaulting to ``"H3"`` when unspecified.
57
+ """
58
+ mode = self.config["mode"]
59
+ if mode is None:
60
+ mode = "H3"
61
+ return mode
62
+
63
+ def set_base_path(self, base_path: Path):
64
+ """Persist an externally provided root directory.
65
+
66
+ Args:
67
+ base_path (Path): Directory serving as the root for pattern paths.
68
+
69
+ Returns:
70
+ None
71
+ """
72
+ self.base_path = base_path
73
+
74
+ def set_pattern(self, pattern: str):
75
+ """Load the configuration block associated with ``pattern``.
76
+
77
+ Args:
78
+ pattern (str): Key in ``assoc`` (e.g., ``'Udemy-2-file'``).
79
+
80
+ Returns:
81
+ dict | None: Selected configuration or ``None`` when unknown.
82
+ """
83
+ self.pattern = pattern
84
+ if pattern not in self.assoc:
85
+ return None
86
+ self.config = self.assoc[pattern]
87
+ return self.config
88
+
89
+ def get_files(self) -> List[Path]:
90
+ """Resolve the files or directory contents defined by the pattern.
91
+
92
+ Returns:
93
+ List[Path]: Concrete file paths ready for scraping.
94
+ """
95
+ if len(self.config) == 0:
96
+ return []
97
+ else:
98
+ dir_path = self.base_path / Path(*self.config["dir"])
99
+
100
+ if self.config["kind"] == "file":
101
+ # 指定されたファイルのみを返す
102
+ files = self.config.get("files", [])
103
+ return [dir_path / file for file in files]
104
+ else:
105
+ # 指定ディレクトリの直下に存在するファイルの一覧を返す
106
+ if not dir_path.exists() or not dir_path.is_dir():
107
+ return []
108
+ files = [f for f in dir_path.iterdir() if f.is_file()]
109
+ return sorted(files)
@@ -0,0 +1,24 @@
1
+ from pathlib import Path
2
+
3
+ from bs4 import BeautifulSoup
4
+
5
+
6
+ class Info:
7
+ def __init__(self, file_path: Path, name: str, soup: BeautifulSoup, append_count: int, no_append_count: int):
8
+ """Bundle parsed HTML and bookkeeping counters.
9
+
10
+ Args:
11
+ file_path (Path): Source HTML path.
12
+ name (str): Friendly identifier, typically the filename.
13
+ soup (BeautifulSoup): Parsed DOM tree to inspect.
14
+ append_count (int): Number of records added so far.
15
+ no_append_count (int): Number of skipped records.
16
+
17
+ Returns:
18
+ None
19
+ """
20
+ self.file_path = file_path
21
+ self.name = name
22
+ self.soup = soup
23
+ self.append_count = append_count
24
+ self.no_append_count = no_append_count