yklibpy 0.1.49__tar.gz → 0.2.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.
- yklibpy-0.2.0/.python-version +1 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/PKG-INFO +2 -2
- {yklibpy-0.1.49 → yklibpy-0.2.0}/mypy.ini +39 -39
- {yklibpy-0.1.49 → yklibpy-0.2.0}/pyproject.toml +2 -2
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/safedict.py +3 -3
- yklibpy-0.2.0/src/yklibpy/common/timex.py +9 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/util_json.py +16 -16
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/util_yaml.py +1 -1
- yklibpy-0.2.0/src/yklibpy/config/__init__.py +3 -0
- yklibpy-0.2.0/src/yklibpy/config/appconfig.py +65 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/db/__init__.py +18 -7
- yklibpy-0.2.0/src/yklibpy/db/appstore.py +120 -0
- yklibpy-0.2.0/src/yklibpy/db/storex.py +56 -0
- yklibpy-0.2.0/src/yklibpy/htmlparser/__init__.py +27 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/app.py +2 -22
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/misc/__init__.py +6 -6
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/misc/anchortaginfo.py +28 -26
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/misc/anchortagx.py +26 -24
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/misc/priceinfo.py +17 -17
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/misc/tagx.py +30 -30
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/tomlop/fileitem.py +41 -41
- {yklibpy-0.1.49 → yklibpy-0.2.0}/uv.lock +10 -10
- yklibpy-0.1.49/.python-version +0 -1
- yklibpy-0.1.49/src/yklibpy/htmlparser/__init__.py +0 -40
- yklibpy-0.1.49/src/yklibpy/htmlparser/amazonsavedcartscraper.py +0 -116
- yklibpy-0.1.49/src/yklibpy/htmlparser/fanzadoujinbasketscraper.py +0 -251
- yklibpy-0.1.49/src/yklibpy/htmlparser/fanzadoujinpurchasedscraper.py +0 -125
- yklibpy-0.1.49/src/yklibpy/htmlparser/kuscraper.py +0 -62
- yklibpy-0.1.49/src/yklibpy/htmlparser/udemyscraper.py +0 -190
- {yklibpy-0.1.49 → yklibpy-0.2.0}/.claude/settings.local.json +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/.editorconfig +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/.gitignore +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/.prettierrc +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/CLAUDE.md +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/README.md +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/db.yaml +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/__init__.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/env.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/info.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/common/util.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/db/db_base.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/db/db_yaml.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/configprepare.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/htmlop.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/preparex.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/progress.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/htmlparser/scraper.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/py.typed +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/tomlop/__init__.py +0 -0
- {yklibpy-0.1.49 → yklibpy-0.2.0}/src/yklibpy/tomlop/tomlop.py +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: yklibpy
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Utilty Library by ykominami
|
|
5
5
|
Project-URL: Homepage, https://github.com/ykominami/yklibpy
|
|
6
6
|
Project-URL: Repository, https://github.com/ykominami/yklibpy
|
|
@@ -10,7 +10,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
14
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
15
15
|
Requires-Python: >=3.14
|
|
16
16
|
Requires-Dist: bs4>=0.0.2
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
[mypy]
|
|
2
|
-
mypy_path = src
|
|
3
|
-
namespace_packages = True
|
|
4
|
-
explicit_package_bases = True
|
|
5
|
-
check_untyped_defs = True
|
|
6
|
-
|
|
7
|
-
[mypy-yklibpy.htmlparser.scraper.*]
|
|
8
|
-
ignore_errors = False
|
|
9
|
-
[fanzadoujinbasketscraper.*]
|
|
10
|
-
ignore_errors = False
|
|
11
|
-
[util.*]
|
|
12
|
-
ignore_errors = False
|
|
13
|
-
[udemyscraper.*]
|
|
14
|
-
ignore_errors = False
|
|
15
|
-
[kuscraper.*]
|
|
16
|
-
ignore_errors = False
|
|
17
|
-
[amazon_saved_cart_scraper.*]
|
|
18
|
-
ignore_errors = False
|
|
19
|
-
[htmlop.*]
|
|
20
|
-
ignore_errors = False
|
|
21
|
-
[misc.*]
|
|
22
|
-
ignore_errors = False
|
|
23
|
-
[price_info.*]
|
|
24
|
-
ignore_errors = False
|
|
25
|
-
[tagx.*]
|
|
26
|
-
ignore_errors = False
|
|
27
|
-
[util_yaml.*]
|
|
28
|
-
ignore_errors = False
|
|
29
|
-
[work_info.*]
|
|
30
|
-
ignore_errors = False
|
|
31
|
-
[ymain.*]
|
|
32
|
-
ignore_errors = False
|
|
33
|
-
[zmain.*]
|
|
34
|
-
ignore_errors = False
|
|
35
|
-
[db_yaml.*]
|
|
36
|
-
ignore_errors = False
|
|
37
|
-
|
|
38
|
-
# [mypy-untyped_package.*]
|
|
39
|
-
# follow_untyped_imports = True
|
|
1
|
+
[mypy]
|
|
2
|
+
mypy_path = src
|
|
3
|
+
namespace_packages = True
|
|
4
|
+
explicit_package_bases = True
|
|
5
|
+
check_untyped_defs = True
|
|
6
|
+
|
|
7
|
+
[mypy-yklibpy.htmlparser.scraper.*]
|
|
8
|
+
ignore_errors = False
|
|
9
|
+
[fanzadoujinbasketscraper.*]
|
|
10
|
+
ignore_errors = False
|
|
11
|
+
[util.*]
|
|
12
|
+
ignore_errors = False
|
|
13
|
+
[udemyscraper.*]
|
|
14
|
+
ignore_errors = False
|
|
15
|
+
[kuscraper.*]
|
|
16
|
+
ignore_errors = False
|
|
17
|
+
[amazon_saved_cart_scraper.*]
|
|
18
|
+
ignore_errors = False
|
|
19
|
+
[htmlop.*]
|
|
20
|
+
ignore_errors = False
|
|
21
|
+
[misc.*]
|
|
22
|
+
ignore_errors = False
|
|
23
|
+
[price_info.*]
|
|
24
|
+
ignore_errors = False
|
|
25
|
+
[tagx.*]
|
|
26
|
+
ignore_errors = False
|
|
27
|
+
[util_yaml.*]
|
|
28
|
+
ignore_errors = False
|
|
29
|
+
[work_info.*]
|
|
30
|
+
ignore_errors = False
|
|
31
|
+
[ymain.*]
|
|
32
|
+
ignore_errors = False
|
|
33
|
+
[zmain.*]
|
|
34
|
+
ignore_errors = False
|
|
35
|
+
[db_yaml.*]
|
|
36
|
+
ignore_errors = False
|
|
37
|
+
|
|
38
|
+
# [mypy-untyped_package.*]
|
|
39
|
+
# follow_untyped_imports = True
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "yklibpy"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
description = "Utilty Library by ykominami"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -23,7 +23,7 @@ classifiers = [
|
|
|
23
23
|
"Intended Audience :: Developers",
|
|
24
24
|
"License :: OSI Approved :: MIT License",
|
|
25
25
|
"Programming Language :: Python :: 3",
|
|
26
|
-
"Programming Language :: Python :: 3.
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
27
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
28
28
|
]
|
|
29
29
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
class SafeDict(dict):
|
|
2
|
-
def __missing__(self, key):
|
|
3
|
-
return f"{{{key}}}"
|
|
1
|
+
class SafeDict(dict):
|
|
2
|
+
def __missing__(self, key):
|
|
3
|
+
return f"{{{key}}}"
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class UtilJson:
|
|
5
|
-
@classmethod
|
|
6
|
-
def load_file(cls, file_name: str):
|
|
7
|
-
data = None
|
|
8
|
-
with open(file_name, "r", encoding="utf-8") as f:
|
|
9
|
-
data = json.load(f)
|
|
10
|
-
return data
|
|
11
|
-
|
|
12
|
-
@classmethod
|
|
13
|
-
def load_string(cls, string: str):
|
|
14
|
-
data = None
|
|
15
|
-
data = json.loads(string)
|
|
16
|
-
return data
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class UtilJson:
|
|
5
|
+
@classmethod
|
|
6
|
+
def load_file(cls, file_name: str):
|
|
7
|
+
data = None
|
|
8
|
+
with open(file_name, "r", encoding="utf-8") as f:
|
|
9
|
+
data = json.load(f)
|
|
10
|
+
return data
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def load_string(cls, string: str):
|
|
14
|
+
data = None
|
|
15
|
+
data = json.loads(string)
|
|
16
|
+
return data
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
class AppConfig:
|
|
2
|
+
FILE_TYPE_YAML = "YAML"
|
|
3
|
+
FILE_TYPE_JSON = "JSON"
|
|
4
|
+
|
|
5
|
+
file_type_dict = {
|
|
6
|
+
FILE_TYPE_YAML: ".yml",
|
|
7
|
+
FILE_TYPE_JSON: ".json",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
file_assoc = {
|
|
11
|
+
"config": {
|
|
12
|
+
"config": {
|
|
13
|
+
"file_type": FILE_TYPE_YAML,
|
|
14
|
+
"ext_name": "",
|
|
15
|
+
"file": "",
|
|
16
|
+
"value": "",
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"db": {
|
|
20
|
+
"db": {
|
|
21
|
+
"file_type": FILE_TYPE_YAML,
|
|
22
|
+
"ext_name": "",
|
|
23
|
+
"file": "",
|
|
24
|
+
"value": "",
|
|
25
|
+
},
|
|
26
|
+
"fetch": {
|
|
27
|
+
"file_type": FILE_TYPE_YAML,
|
|
28
|
+
"ext_name": "",
|
|
29
|
+
"file": "",
|
|
30
|
+
"value": "",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
default_json_fields_in_db = [
|
|
35
|
+
"name",
|
|
36
|
+
"count",
|
|
37
|
+
"valid",
|
|
38
|
+
"url",
|
|
39
|
+
"owner",
|
|
40
|
+
"nameWithOwner",
|
|
41
|
+
"parent",
|
|
42
|
+
"pullRequests",
|
|
43
|
+
"createdAt",
|
|
44
|
+
"description",
|
|
45
|
+
"diskUsage",
|
|
46
|
+
"hasProjectsEnabled",
|
|
47
|
+
"homepageUrl",
|
|
48
|
+
]
|
|
49
|
+
default_json_fields = [
|
|
50
|
+
"name",
|
|
51
|
+
"url",
|
|
52
|
+
"owner",
|
|
53
|
+
"nameWithOwner",
|
|
54
|
+
"parent",
|
|
55
|
+
"pullRequests",
|
|
56
|
+
"createdAt",
|
|
57
|
+
"description",
|
|
58
|
+
"diskUsage",
|
|
59
|
+
"hasProjectsEnabled",
|
|
60
|
+
"homepageUrl",
|
|
61
|
+
]
|
|
62
|
+
fetch_item = {
|
|
63
|
+
"date": "",
|
|
64
|
+
}
|
|
65
|
+
key = "JSON_FIELDS"
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
from yklibpy.db.db_base import DbBase
|
|
2
2
|
from yklibpy.db.db_yaml import DbYaml
|
|
3
|
+
from yklibpy.db.storex import Storex
|
|
4
|
+
from yklibpy.db.appstore import AppStore
|
|
3
5
|
|
|
4
|
-
__all__ = [
|
|
6
|
+
__all__ = [
|
|
7
|
+
"DbBase",
|
|
8
|
+
"DbYaml",
|
|
9
|
+
"Storex",
|
|
10
|
+
"AppStore",
|
|
11
|
+
"get_or_create_db",
|
|
12
|
+
"db_yaml",
|
|
13
|
+
"db_yaml_x",
|
|
14
|
+
]
|
|
5
15
|
|
|
6
|
-
|
|
16
|
+
|
|
17
|
+
def get_or_create_db(kind: str, fname: str) -> DbYaml | None:
|
|
7
18
|
if kind.lower() == "yaml":
|
|
8
19
|
db = DbYaml(fname)
|
|
9
20
|
else:
|
|
10
21
|
db = None
|
|
11
22
|
return db
|
|
12
23
|
|
|
24
|
+
|
|
13
25
|
def db_yaml_x() -> DbYaml:
|
|
14
26
|
return db_yaml("db.yml")
|
|
15
27
|
|
|
16
|
-
|
|
17
|
-
|
|
28
|
+
|
|
29
|
+
def db_yaml(db_file: str) -> DbYaml:
|
|
30
|
+
db = get_or_create_db("yaml", db_file)
|
|
18
31
|
if db is None:
|
|
19
32
|
raise ValueError("Failed to create database")
|
|
20
33
|
db.load()
|
|
@@ -23,9 +36,7 @@ def db_yaml(db_file:str) -> DbYaml:
|
|
|
23
36
|
return db
|
|
24
37
|
|
|
25
38
|
|
|
26
|
-
__all__ = ["DbYaml", "get_or_create_db", "db_yaml"]
|
|
27
|
-
|
|
28
39
|
if __name__ == "__main__":
|
|
29
40
|
fname = "db.yaml"
|
|
30
|
-
db = get_or_create_db("
|
|
41
|
+
db = get_or_create_db("yaml", fname)
|
|
31
42
|
print(f"db={db}")
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
from yklibpy.db.storex import Storex
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AppStore:
|
|
9
|
+
def __init__(self, prog_name: str, assoc: dict[str, dict[str, str]]) -> None:
|
|
10
|
+
self.home_path = Path.home()
|
|
11
|
+
self.prog_name = prog_name
|
|
12
|
+
self.assoc = assoc
|
|
13
|
+
self.set_ext_name()
|
|
14
|
+
|
|
15
|
+
def set_ext_name(self):
|
|
16
|
+
for kind in self.assoc:
|
|
17
|
+
for base_name in self.assoc[kind]:
|
|
18
|
+
self.assoc[kind][base_name]["ext_name"] = Storex.get_ext_name(
|
|
19
|
+
self.assoc[kind][base_name]["file_type"]
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def prepare_config_file_and_db_file(self):
|
|
23
|
+
for kind in self.assoc:
|
|
24
|
+
for base_name in self.assoc[kind]:
|
|
25
|
+
file_item_assoc = self.assoc[kind][base_name]
|
|
26
|
+
file = self.get_file(kind, base_name, file_item_assoc)
|
|
27
|
+
self.assoc[kind][base_name]["file"] = file
|
|
28
|
+
|
|
29
|
+
return self.assoc
|
|
30
|
+
|
|
31
|
+
def load_file(self):
|
|
32
|
+
for kind in self.assoc:
|
|
33
|
+
for base_name in self.assoc[kind]:
|
|
34
|
+
self.assoc[kind][base_name]["value"] = self.assoc[kind][base_name][
|
|
35
|
+
"file"
|
|
36
|
+
].load()
|
|
37
|
+
|
|
38
|
+
def get_assoc_from_config(self, base_name: str) -> Any:
|
|
39
|
+
return self.assoc["config"][base_name]["value"]
|
|
40
|
+
|
|
41
|
+
def get_assoc_from_db(self, base_name: str) -> Any:
|
|
42
|
+
return self.assoc["db"][base_name]["value"]
|
|
43
|
+
|
|
44
|
+
def get_file(self, kind: str, base_name: str, assoc: dist[str, str]):
|
|
45
|
+
file = ""
|
|
46
|
+
if kind == "config":
|
|
47
|
+
file = self.get_config_file(base_name, assoc)
|
|
48
|
+
else:
|
|
49
|
+
file = self.get_db_file(base_name, assoc)
|
|
50
|
+
|
|
51
|
+
return file
|
|
52
|
+
|
|
53
|
+
def get_config_file(self, key: str, assoc: dist[str, str]):
|
|
54
|
+
if sys.platform == "win32":
|
|
55
|
+
# Windows: APPDATA / LOCALAPPDATA
|
|
56
|
+
file_name_array = self.get_config_file_for_win(key, assoc["ext_name"])
|
|
57
|
+
else:
|
|
58
|
+
# Linux/macOS: XDG規約
|
|
59
|
+
file_name_array = self.get_config_file_for_unix(key, assoc["ext_name"])
|
|
60
|
+
|
|
61
|
+
file = Storex(assoc["file_type"], file_name_array)
|
|
62
|
+
return file
|
|
63
|
+
|
|
64
|
+
def get_db_file(self, key: str, assoc: dist[str, str]):
|
|
65
|
+
file_name_array = []
|
|
66
|
+
if sys.platform == "win32":
|
|
67
|
+
# Windows: APPDATA / LOCALAPPDATA
|
|
68
|
+
file_name_array = self.get_db_file_for_win(key, assoc["ext_name"])
|
|
69
|
+
else:
|
|
70
|
+
# Linux/macOS: XDG規約
|
|
71
|
+
file_name_array = self.get_db_file_for_unix(key, assoc["ext_name"])
|
|
72
|
+
|
|
73
|
+
file = Storex(assoc["file_type"], file_name_array)
|
|
74
|
+
return file
|
|
75
|
+
|
|
76
|
+
def get_config_file_for_win(self, base_name: str, ext_name: str):
|
|
77
|
+
config_top_dir = Path(
|
|
78
|
+
os.environ.get("APPDATA", str(self.home_path / "AppData" / "Roaming"))
|
|
79
|
+
)
|
|
80
|
+
file_name = f"{base_name}{ext_name}"
|
|
81
|
+
config_file_name_array = [str(config_top_dir), self.prog_name, file_name]
|
|
82
|
+
return config_file_name_array
|
|
83
|
+
|
|
84
|
+
def get_db_file_for_win(self, base_name: str, ext_name: str):
|
|
85
|
+
data_top_dir = Path(
|
|
86
|
+
os.environ.get("LOCALAPPDATA", str(self.home_path / "AppData" / "Local"))
|
|
87
|
+
)
|
|
88
|
+
file_name = f"{base_name}{ext_name}"
|
|
89
|
+
db_file_name_array = [str(data_top_dir), self.prog_name, file_name]
|
|
90
|
+
return db_file_name_array
|
|
91
|
+
|
|
92
|
+
def get_config_file_for_unix(self, base_name: str, ext_name: str):
|
|
93
|
+
file_name = f"{base_name}{ext_name}"
|
|
94
|
+
config_file_name_array = [
|
|
95
|
+
str(self.home_path),
|
|
96
|
+
".config",
|
|
97
|
+
self.prog_name,
|
|
98
|
+
file_name,
|
|
99
|
+
]
|
|
100
|
+
return config_file_name_array
|
|
101
|
+
|
|
102
|
+
def get_db_file_for_unix(self, base_name: str, ext_name: str):
|
|
103
|
+
file_name = f"{base_name}{ext_name}"
|
|
104
|
+
db_file_name_array = [
|
|
105
|
+
str(self.home_path),
|
|
106
|
+
".local",
|
|
107
|
+
"share",
|
|
108
|
+
self.prog_name,
|
|
109
|
+
file_name,
|
|
110
|
+
]
|
|
111
|
+
return db_file_name_array
|
|
112
|
+
|
|
113
|
+
def get_from_config(self, base_name: str, key: str) -> Any:
|
|
114
|
+
return self.assoc["config"][base_name]["value"][key]
|
|
115
|
+
|
|
116
|
+
def output_config(self, key: str, data: dict[str, Any]) -> None:
|
|
117
|
+
self.assoc["config"][key]["file"].output(data)
|
|
118
|
+
|
|
119
|
+
def output_db(self, key: str, data: dict[str, Any]) -> None:
|
|
120
|
+
self.assoc["db"][key]["file"].output(data)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import yaml
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from yklibpy.config.appconfig import AppConfig
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Storex:
|
|
10
|
+
_file_type_dict: dict[str, str] = {}
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def set_file_type_dict(cls, file_type_dict: dict[str, str]) -> None:
|
|
14
|
+
cls._file_type_dict = file_type_dict
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def get_ext_name(cls, file_type: str) -> str:
|
|
18
|
+
return cls._file_type_dict[file_type]
|
|
19
|
+
|
|
20
|
+
def __init__(self, file_type: str, file_name_array: list[str] | None = None):
|
|
21
|
+
self.file_name_array = file_name_array or []
|
|
22
|
+
self.file_type = file_type
|
|
23
|
+
|
|
24
|
+
# file_name_arrayは完全なパス要素の配列(呼び出し元で構築済み)
|
|
25
|
+
self.file_path = Path(*self.file_name_array) if self.file_name_array else Path()
|
|
26
|
+
|
|
27
|
+
self.store: dict[str, str] = {}
|
|
28
|
+
|
|
29
|
+
def get_value(self, key: str) -> Any:
|
|
30
|
+
return self.store.get(key)
|
|
31
|
+
|
|
32
|
+
def get_store(self) -> dict[str, Any]:
|
|
33
|
+
return self.store
|
|
34
|
+
|
|
35
|
+
def load(self) -> dict[str, Any]:
|
|
36
|
+
if self.file_path.exists():
|
|
37
|
+
with open(self.file_path, "r", encoding="utf-8") as f:
|
|
38
|
+
if self.file_type == AppConfig.FILE_TYPE_YAML:
|
|
39
|
+
self.store = yaml.safe_load(f) or {}
|
|
40
|
+
elif self.file_type == AppConfig.FILE_TYPE_JSON:
|
|
41
|
+
self.store = json.load(f)
|
|
42
|
+
else:
|
|
43
|
+
self.store = {"_lines": f.readlines()}
|
|
44
|
+
|
|
45
|
+
return self.store
|
|
46
|
+
|
|
47
|
+
def output(self, data: Any) -> None:
|
|
48
|
+
# 親ディレクトリが存在しない場合は作成
|
|
49
|
+
self.file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
with open(self.file_path, "w", encoding="utf-8") as f:
|
|
51
|
+
if self.file_type == AppConfig.FILE_TYPE_YAML:
|
|
52
|
+
yaml.dump(data, f, allow_unicode=True)
|
|
53
|
+
elif self.file_type == AppConfig.FILE_TYPE_JSON:
|
|
54
|
+
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
55
|
+
else:
|
|
56
|
+
f.write(str(data))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from yklibpy.htmlparser.app import App
|
|
2
|
+
from yklibpy.htmlparser.preparex import Preparex
|
|
3
|
+
from yklibpy.htmlparser.progress import Progress
|
|
4
|
+
from yklibpy.htmlparser.scraper import Scraper
|
|
5
|
+
from yklibpy.htmlparser.htmlop import HtmlOp
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"App",
|
|
9
|
+
"Progress",
|
|
10
|
+
"Scraper",
|
|
11
|
+
"Preparex",
|
|
12
|
+
"HtmlOp",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def xmain() -> str:
|
|
17
|
+
print("Hello from yklibpy!")
|
|
18
|
+
return "Hello from yklibpy!"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def ymain() -> str:
|
|
22
|
+
print("Y Hello from yklibpy!")
|
|
23
|
+
return "Y Hello from yklibpy!"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
xmain()
|
|
@@ -2,12 +2,7 @@ from pathlib import Path
|
|
|
2
2
|
from typing import List
|
|
3
3
|
|
|
4
4
|
from yklibpy.common.env import Env
|
|
5
|
-
from yklibpy.htmlparser.amazonsavedcartscraper import AmazonSavedCartScraper
|
|
6
|
-
from yklibpy.htmlparser.fanzadoujinbasketscraper import FanzaDoujinBasketScraper
|
|
7
|
-
from yklibpy.htmlparser.fanzadoujinpurchasedscraper import FanzaDoujinPurchasedScraper
|
|
8
|
-
from yklibpy.htmlparser.kuscraper import KUScraper
|
|
9
5
|
from yklibpy.htmlparser.scraper import Scraper
|
|
10
|
-
from yklibpy.htmlparser.udemyscraper import UdemyScraper
|
|
11
6
|
|
|
12
7
|
|
|
13
8
|
class App:
|
|
@@ -37,23 +32,8 @@ class App:
|
|
|
37
32
|
Scraper: Concrete scraper that knows how to parse the given site, or
|
|
38
33
|
``None`` when the mode is unsupported.
|
|
39
34
|
"""
|
|
40
|
-
print(f"mode={mode}")
|
|
41
|
-
|
|
42
|
-
return UdemyScraper(sequence)
|
|
43
|
-
# return H3Scraper()
|
|
44
|
-
# return AScraper()
|
|
45
|
-
elif mode == "ku":
|
|
46
|
-
return KUScraper(sequence)
|
|
47
|
-
elif mode == "fanza_doujin_basket":
|
|
48
|
-
return FanzaDoujinBasketScraper(sequence)
|
|
49
|
-
elif mode == "fanza_doujin_purchased":
|
|
50
|
-
return FanzaDoujinPurchasedScraper(sequence)
|
|
51
|
-
elif mode == "amazon_saved_cart":
|
|
52
|
-
# print(f'mode={mode}')
|
|
53
|
-
return AmazonSavedCartScraper(sequence)
|
|
54
|
-
else:
|
|
55
|
-
print(f"mode={mode} is not supported")
|
|
56
|
-
return None
|
|
35
|
+
print(f"mode={mode} is not supported")
|
|
36
|
+
return None
|
|
57
37
|
|
|
58
38
|
def loop(self, files: List[Path], mode: str, sequence: int):
|
|
59
39
|
"""Iterate through HTML files and accumulate extracted link metadata.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from yklibpy.htmlparser.misc.anchortaginfo import AnchorTagInfo
|
|
2
|
-
from yklibpy.htmlparser.misc.anchortagx import AnchorTagx
|
|
3
|
-
from yklibpy.htmlparser.misc.priceinfo import PriceInfo
|
|
4
|
-
from yklibpy.htmlparser.misc.tagx import Tagx
|
|
5
|
-
|
|
6
|
-
__all__ = ["AnchorTagInfo", "AnchorTagx", "PriceInfo", "Tagx"]
|
|
1
|
+
from yklibpy.htmlparser.misc.anchortaginfo import AnchorTagInfo
|
|
2
|
+
from yklibpy.htmlparser.misc.anchortagx import AnchorTagx
|
|
3
|
+
from yklibpy.htmlparser.misc.priceinfo import PriceInfo
|
|
4
|
+
from yklibpy.htmlparser.misc.tagx import Tagx
|
|
5
|
+
|
|
6
|
+
__all__ = ["AnchorTagInfo", "AnchorTagx", "PriceInfo", "Tagx"]
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
self.
|
|
12
|
-
self.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
self.parent_parent =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
self.
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from bs4.element import PageElement
|
|
4
|
+
|
|
5
|
+
from yklibpy.htmlparser.misc.anchortagx import AnchorTagx
|
|
6
|
+
from yklibpy.htmlparser.misc.tagx import Tagx
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AnchorTagInfo:
|
|
10
|
+
def __init__(self, anchor_tag: Optional[PageElement]):
|
|
11
|
+
self.anchor = AnchorTagx(anchor_tag)
|
|
12
|
+
self.parent_parent: Optional[Tagx] = None
|
|
13
|
+
self.parent: Optional[Tagx] = None
|
|
14
|
+
self.next_sibling: Optional[Tagx] = None
|
|
15
|
+
|
|
16
|
+
def setup(self):
|
|
17
|
+
# print()
|
|
18
|
+
if self.anchor.tag is not None:
|
|
19
|
+
self.next_sibling = Tagx(self.anchor.tag.next_sibling, "next_sibling")
|
|
20
|
+
self.parent = Tagx(self.anchor.tag.next_sibling, "parent")
|
|
21
|
+
if self.anchor.tag.parent is not None:
|
|
22
|
+
self.parent_parent = Tagx(self.anchor.tag.parent.parent, "parent.parent")
|
|
23
|
+
else:
|
|
24
|
+
self.parent_parent = None
|
|
25
|
+
else:
|
|
26
|
+
self.next_sibling = None
|
|
27
|
+
self.parent = None
|
|
28
|
+
self.parent_parent = None
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
from bs4.element import PageElement
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
self.href = ""
|
|
16
|
-
|
|
17
|
-
self.
|
|
18
|
-
|
|
19
|
-
self.text =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from bs4.element import PageElement
|
|
4
|
+
|
|
5
|
+
from yklibpy.htmlparser.misc.tagx import Tagx
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AnchorTagx(Tagx):
|
|
9
|
+
def __init__(self, anchor_tag: Optional[PageElement]):
|
|
10
|
+
super().__init__(anchor_tag, "anchor")
|
|
11
|
+
self.href: str = ""
|
|
12
|
+
self.text: str = ""
|
|
13
|
+
if self.tag is not None:
|
|
14
|
+
if hasattr(self.tag, "get"):
|
|
15
|
+
self.href = self.tag.get("href", "")
|
|
16
|
+
else:
|
|
17
|
+
self.href = ""
|
|
18
|
+
if hasattr(self.tag, "get_text"):
|
|
19
|
+
self.text = self.tag.get_text(strip=True)
|
|
20
|
+
else:
|
|
21
|
+
self.text = ""
|
|
22
|
+
self.mes_href: str = f" href: {self.href}"
|
|
23
|
+
self.mes_text: str = f" text: {self.text}"
|
|
24
|
+
|
|
25
|
+
def show(self) -> str:
|
|
26
|
+
return "\n".join([self.mes_href, self.mes_text])
|