yklibpy 0.2.2__tar.gz → 0.2.5__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.2 → yklibpy-0.2.5}/PKG-INFO +1 -1
- {yklibpy-0.2.2 → yklibpy-0.2.5}/pyproject.toml +1 -1
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/cli/cli.py +7 -5
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/command/command.py +23 -1
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/env.py +3 -3
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/util.py +41 -2
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/util_yaml.py +1 -1
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/config/appconfig.py +6 -6
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/db/__init__.py +1 -1
- yklibpy-0.2.5/src/yklibpy/db/appstore.py +201 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/db/storex.py +13 -6
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/app.py +9 -7
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/htmlop.py +1 -1
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/preparex.py +15 -15
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/tomlop/tomlop.py +15 -11
- {yklibpy-0.2.2 → yklibpy-0.2.5}/uv.lock +1 -1
- yklibpy-0.2.2/src/yklibpy/db/appstore.py +0 -120
- {yklibpy-0.2.2 → yklibpy-0.2.5}/.claude/settings.local.json +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/.editorconfig +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/.gitignore +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/.prettierrc +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/.python-version +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/CLAUDE.md +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/README.md +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/db.yaml +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/mypy.ini +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/cli/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/command/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/info.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/safedict.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/timex.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/common/util_json.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/config/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/db/db_base.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/db/db_yaml.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/configprepare.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/misc/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/misc/anchortaginfo.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/misc/anchortagx.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/misc/priceinfo.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/misc/tagx.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/progress.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/htmlparser/scraper.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/py.typed +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/tomlop/__init__.py +0 -0
- {yklibpy-0.2.2 → yklibpy-0.2.5}/src/yklibpy/tomlop/fileitem.py +0 -0
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import argparse
|
|
2
|
-
from typing import Any
|
|
3
2
|
|
|
4
|
-
from yklibpy.db.appstore import AppStore
|
|
5
3
|
|
|
6
4
|
class Cli:
|
|
7
5
|
def __init__(self, help_text: str) -> None:
|
|
8
6
|
self.parser = argparse.ArgumentParser(
|
|
9
7
|
description=help_text
|
|
10
8
|
)
|
|
9
|
+
self.args: argparse.Namespace | None = None
|
|
11
10
|
|
|
12
|
-
def
|
|
11
|
+
def get_parser(self) -> argparse.ArgumentParser:
|
|
12
|
+
return self.parser
|
|
13
|
+
|
|
14
|
+
def get_args(self) -> argparse.Namespace | None:
|
|
13
15
|
return self.args
|
|
14
16
|
|
|
15
|
-
def parse_args(self):
|
|
17
|
+
def parse_args(self) -> argparse.Namespace:
|
|
16
18
|
self.args = self.parser.parse_args()
|
|
17
19
|
return self.args
|
|
18
20
|
|
|
19
|
-
def get_subparsers(self,
|
|
21
|
+
def get_subparsers(self, name: str) -> argparse._SubParsersAction[argparse.ArgumentParser]:
|
|
20
22
|
self.subparsers = self.parser.add_subparsers(dest=name, required=True)
|
|
21
23
|
return self.subparsers
|
|
@@ -2,8 +2,10 @@ import logging
|
|
|
2
2
|
import subprocess
|
|
3
3
|
from typing import Any, Optional
|
|
4
4
|
|
|
5
|
+
from yklibpy.common.timex import Timex
|
|
6
|
+
|
|
5
7
|
class Command:
|
|
6
|
-
def __init__():
|
|
8
|
+
def __init__(self) -> None:
|
|
7
9
|
pass
|
|
8
10
|
|
|
9
11
|
def run_command(
|
|
@@ -56,6 +58,8 @@ class Command:
|
|
|
56
58
|
except subprocess.SubprocessError:
|
|
57
59
|
raise
|
|
58
60
|
|
|
61
|
+
return ["std_out", "std_error"]
|
|
62
|
+
|
|
59
63
|
def run_command_simple(self, command: str | list[str], shell: bool = False) -> str:
|
|
60
64
|
"""
|
|
61
65
|
コマンドラインを実行して、標準出力への出力を文字列として受け取る(シンプル版)。
|
|
@@ -96,6 +100,24 @@ class Command:
|
|
|
96
100
|
stderr=e.stderr.decode("utf-8") if e.stderr else "",
|
|
97
101
|
)
|
|
98
102
|
'''
|
|
103
|
+
return "error"
|
|
104
|
+
|
|
105
|
+
def get_next_count(self, fetch_assoc: dict[int, str]) -> tuple[int, dict[int, str]]:
|
|
106
|
+
if fetch_assoc is None:
|
|
107
|
+
num = 1
|
|
108
|
+
fetch_assoc = {num: ""}
|
|
109
|
+
next_count = num
|
|
110
|
+
else:
|
|
111
|
+
num = 0
|
|
112
|
+
for item in fetch_assoc:
|
|
113
|
+
item_num = int(item)
|
|
114
|
+
if item_num > num:
|
|
115
|
+
num = item_num
|
|
116
|
+
|
|
117
|
+
next_count = num + 1
|
|
118
|
+
fetch_assoc[next_count] = Timex.get_now()
|
|
119
|
+
|
|
120
|
+
return (next_count, fetch_assoc)
|
|
99
121
|
|
|
100
122
|
def array_to_dict(
|
|
101
123
|
self, data: list[dict[str, Any]], key: str
|
|
@@ -87,14 +87,14 @@ class Env:
|
|
|
87
87
|
Returns:
|
|
88
88
|
List[Path]: Concrete file paths ready for scraping.
|
|
89
89
|
"""
|
|
90
|
-
print("env:get_files")
|
|
90
|
+
# print("env:get_files")
|
|
91
91
|
if len(self.config) == 0:
|
|
92
|
-
print("0 env:get_files")
|
|
92
|
+
# print("0 env:get_files")
|
|
93
93
|
self.sequence = -1
|
|
94
94
|
return []
|
|
95
95
|
else:
|
|
96
96
|
dir_path = self.base_path / Path(*self.config["dir"])
|
|
97
|
-
print(f"2 env:get_files dir_path={dir_path}")
|
|
97
|
+
# print(f"2 env:get_files dir_path={dir_path}")
|
|
98
98
|
self.sequence = int(dir_path.stem)
|
|
99
99
|
|
|
100
100
|
if self.config["kind"] == "file":
|
|
@@ -112,7 +112,7 @@ class Util:
|
|
|
112
112
|
|
|
113
113
|
results: list[Path] = []
|
|
114
114
|
|
|
115
|
-
print(f"base_dir={base_dir}")
|
|
115
|
+
# print(f"base_dir={base_dir}")
|
|
116
116
|
# print(f'pattern={pattern}')
|
|
117
117
|
for path in base_dir.rglob(pattern):
|
|
118
118
|
# print(f'path={path}')
|
|
@@ -123,7 +123,7 @@ class Util:
|
|
|
123
123
|
elif target_type == "both":
|
|
124
124
|
results.append(path)
|
|
125
125
|
|
|
126
|
-
print(f"results={results}")
|
|
126
|
+
# print(f"results={results}")
|
|
127
127
|
return results
|
|
128
128
|
|
|
129
129
|
@classmethod
|
|
@@ -434,6 +434,45 @@ class Util:
|
|
|
434
434
|
record_2["Time"] = "0時間"
|
|
435
435
|
Util.output_tsv(dict_2, output_path)
|
|
436
436
|
|
|
437
|
+
@classmethod
|
|
438
|
+
def remove_crlf(cls, string: str) -> str:
|
|
439
|
+
# 改行文字のみ抽出
|
|
440
|
+
#newlines = [c for c in string if c in ("\n", "\r")]
|
|
441
|
+
newlines = string.replace("\n", "").replace("\r", "")
|
|
442
|
+
return "".join(newlines) # ['\n', '\r', '\n', '\n']
|
|
443
|
+
|
|
444
|
+
@classmethod
|
|
445
|
+
def remove_whitespace(cls, string: str) -> str:
|
|
446
|
+
# 改行文字のみ抽出
|
|
447
|
+
# whitespace = re.findall(r'\s+', string)
|
|
448
|
+
whitespace = "".join(string.split())
|
|
449
|
+
return "".join(whitespace) # ['\n', '\r', '\n', '\n']
|
|
450
|
+
|
|
451
|
+
@classmethod
|
|
452
|
+
def remove_non_printable(cls, string: str) -> str:
|
|
453
|
+
non_printable = [c for c in string if c.isprintable()]
|
|
454
|
+
return "".join(non_printable) # ['\n', '\t', '\x00']
|
|
455
|
+
|
|
456
|
+
@classmethod
|
|
457
|
+
def get_valie_string(cls, string: str|None) -> str:
|
|
458
|
+
if string is None:
|
|
459
|
+
return ""
|
|
460
|
+
if len(string) == 0:
|
|
461
|
+
return ""
|
|
462
|
+
return cls.remove_whitespace(string)
|
|
463
|
+
|
|
464
|
+
@classmethod
|
|
465
|
+
def is_empty(cls, string: str) -> bool:
|
|
466
|
+
valid_string = cls.get_valie_string(string)
|
|
467
|
+
return len(valid_string) == 0
|
|
468
|
+
|
|
469
|
+
@classmethod
|
|
470
|
+
def normalize_string(cls, string: str) -> str | None:
|
|
471
|
+
valid_string = cls.get_valie_string(string)
|
|
472
|
+
if cls.is_empty(valid_string):
|
|
473
|
+
return None
|
|
474
|
+
else:
|
|
475
|
+
return valid_string
|
|
437
476
|
|
|
438
477
|
if __name__ == "__main__":
|
|
439
478
|
# test_util = Util()
|
|
@@ -48,7 +48,7 @@ class UtilYaml:
|
|
|
48
48
|
dict: Parsed YAML content.
|
|
49
49
|
"""
|
|
50
50
|
data = {}
|
|
51
|
-
print(f"input_path={input_path}")
|
|
51
|
+
# print(f"input_path={input_path}")
|
|
52
52
|
with open(input_path, "r", encoding="utf-8") as f:
|
|
53
53
|
data = yaml.load(f, Loader=yaml.FullLoader)
|
|
54
54
|
if data is None:
|
|
@@ -12,22 +12,22 @@ class AppConfig:
|
|
|
12
12
|
"config": {
|
|
13
13
|
"file_type": FILE_TYPE_YAML,
|
|
14
14
|
"ext_name": "",
|
|
15
|
-
"file":
|
|
16
|
-
"value":
|
|
15
|
+
"file": {},
|
|
16
|
+
"value": {},
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"db": {
|
|
20
20
|
"db": {
|
|
21
21
|
"file_type": FILE_TYPE_YAML,
|
|
22
22
|
"ext_name": "",
|
|
23
|
-
"file":
|
|
24
|
-
"value":
|
|
23
|
+
"file": {},
|
|
24
|
+
"value": {},
|
|
25
25
|
},
|
|
26
26
|
"fetch": {
|
|
27
27
|
"file_type": FILE_TYPE_YAML,
|
|
28
28
|
"ext_name": "",
|
|
29
|
-
"file":
|
|
30
|
-
"value":
|
|
29
|
+
"file": {},
|
|
30
|
+
"value": {},
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
33
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from yklibpy.common.util import Util
|
|
7
|
+
from yklibpy.db.storex import Storex
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AppStore:
|
|
11
|
+
def __init__(self, prog_name: str, assoc: dict[str, dict[str, dict[str, Any]]], user: str | None) -> None:
|
|
12
|
+
self.user = Util.normalize_string(user)
|
|
13
|
+
self.home_path = Path.home()
|
|
14
|
+
self.prog_name = prog_name
|
|
15
|
+
self.assoc = assoc
|
|
16
|
+
self.set_ext_name()
|
|
17
|
+
|
|
18
|
+
def set_ext_name(self):
|
|
19
|
+
for kind in self.assoc:
|
|
20
|
+
for base_name in self.assoc[kind]:
|
|
21
|
+
self.assoc[kind][base_name]["ext_name"] = Storex.get_ext_name(
|
|
22
|
+
self.assoc[kind][base_name]["file_type"]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def prepare_config_file_and_db_file(self):
|
|
26
|
+
for kind in self.assoc:
|
|
27
|
+
for base_name in self.assoc[kind]:
|
|
28
|
+
file_item_assoc = self.assoc[kind][base_name]
|
|
29
|
+
file = self.get_file(self.user, kind, base_name, file_item_assoc)
|
|
30
|
+
|
|
31
|
+
# print(f'4 Yklibpy AppStore prepare_config_file_and_db_file self.user={self.user} ')
|
|
32
|
+
# print(f'5 self.assoc[kind][base_name]={self.assoc[kind][base_name]}')
|
|
33
|
+
if self.user is not None:
|
|
34
|
+
self.assoc[kind][base_name]["file"][self.user] = file
|
|
35
|
+
else:
|
|
36
|
+
self.assoc[kind][base_name]["file"] = file
|
|
37
|
+
|
|
38
|
+
return self.assoc
|
|
39
|
+
|
|
40
|
+
def load_file(self) -> None:
|
|
41
|
+
for kind in self.assoc:
|
|
42
|
+
for base_name in self.assoc[kind]:
|
|
43
|
+
if self.user is not None:
|
|
44
|
+
# print(f'1 Yklibpy AppStore load_file self.user={self.user} self.assoc[kind][base_name]={self.assoc[kind][base_name]}')
|
|
45
|
+
self.assoc[kind][base_name]["value"][self.user] = self.assoc[kind][base_name][
|
|
46
|
+
"file"
|
|
47
|
+
][self.user].load()
|
|
48
|
+
else:
|
|
49
|
+
# print(f'2 Yklibpy AppStore load_file self.user={self.user} ')
|
|
50
|
+
self.assoc[kind][base_name]["value"] = self.assoc[kind][base_name][
|
|
51
|
+
"file"
|
|
52
|
+
].load()
|
|
53
|
+
|
|
54
|
+
def get_assoc_from_config(self, base_name: str) -> Any:
|
|
55
|
+
if self.user is not None:
|
|
56
|
+
return self.assoc["config"][base_name]["value"][self.user]
|
|
57
|
+
else:
|
|
58
|
+
return self.assoc["config"][base_name]["value"]
|
|
59
|
+
|
|
60
|
+
def get_assoc_from_db(self, base_name: str) -> Any:
|
|
61
|
+
if self.user is not None:
|
|
62
|
+
return self.assoc["db"][base_name]["value"][self.user]
|
|
63
|
+
else:
|
|
64
|
+
return self.assoc["db"][base_name]["value"]
|
|
65
|
+
|
|
66
|
+
def get_file(self, user: str | None, kind: str, base_name: str, assoc: dict[str, Any]) -> Storex:
|
|
67
|
+
if kind == "config":
|
|
68
|
+
return self.get_config_file(user, base_name, assoc)
|
|
69
|
+
else:
|
|
70
|
+
return self.get_db_file(user, base_name, assoc)
|
|
71
|
+
|
|
72
|
+
def get_config_file(self, user: str | None, key: str, assoc: dict[str, Any]) -> Storex:
|
|
73
|
+
if sys.platform == "win32":
|
|
74
|
+
# Windows: APPDATA / LOCALAPPDATA
|
|
75
|
+
file_name_array = self.get_config_file_for_win(user, key, assoc["ext_name"])
|
|
76
|
+
else:
|
|
77
|
+
# Linux/macOS: XDG規約
|
|
78
|
+
file_name_array = self.get_config_file_for_unix(user, key, assoc["ext_name"])
|
|
79
|
+
|
|
80
|
+
file = Storex(assoc["file_type"], file_name_array)
|
|
81
|
+
return file
|
|
82
|
+
|
|
83
|
+
def get_db_file(self, user: str | None, key: str, assoc: dict[str, Any]) -> Storex:
|
|
84
|
+
file_name_array = []
|
|
85
|
+
if sys.platform == "win32":
|
|
86
|
+
# Windows: APPDATA / LOCALAPPDATA
|
|
87
|
+
file_name_array = self.get_db_file_for_win(user, key, assoc["ext_name"])
|
|
88
|
+
else:
|
|
89
|
+
# Linux/macOS: XDG規約
|
|
90
|
+
file_name_array = self.get_db_file_for_unix(user, key, assoc["ext_name"])
|
|
91
|
+
|
|
92
|
+
file = Storex(assoc["file_type"], file_name_array)
|
|
93
|
+
return file
|
|
94
|
+
|
|
95
|
+
def get_config_file_for_win(self, user: str | None, base_name: str, ext_name: str):
|
|
96
|
+
config_top_dir = Path(
|
|
97
|
+
os.environ.get("APPDATA", str(self.home_path / "AppData" / "Roaming"))
|
|
98
|
+
)
|
|
99
|
+
file_name = f"{base_name}{ext_name}"
|
|
100
|
+
if user is not None:
|
|
101
|
+
config_file_name_array = [str(config_top_dir), self.prog_name, user, file_name]
|
|
102
|
+
else:
|
|
103
|
+
config_file_name_array = [str(config_top_dir), self.prog_name, file_name]
|
|
104
|
+
|
|
105
|
+
return config_file_name_array
|
|
106
|
+
|
|
107
|
+
def get_db_file_for_win(self, user: str | None,base_name: str, ext_name: str):
|
|
108
|
+
data_top_dir = Path(
|
|
109
|
+
os.environ.get("LOCALAPPDATA", str(self.home_path / "AppData" / "Local"))
|
|
110
|
+
)
|
|
111
|
+
file_name = f"{base_name}{ext_name}"
|
|
112
|
+
if user is not None:
|
|
113
|
+
db_file_name_array = [str(data_top_dir), self.prog_name, user, file_name]
|
|
114
|
+
else:
|
|
115
|
+
db_file_name_array = [str(data_top_dir), self.prog_name, file_name]
|
|
116
|
+
|
|
117
|
+
return db_file_name_array
|
|
118
|
+
|
|
119
|
+
def get_config_file_for_unix(self, user: str | None,base_name: str, ext_name: str):
|
|
120
|
+
file_name = f"{base_name}{ext_name}"
|
|
121
|
+
if user is not None:
|
|
122
|
+
config_file_name_array = [
|
|
123
|
+
str(self.home_path),
|
|
124
|
+
".config",
|
|
125
|
+
self.prog_name,
|
|
126
|
+
user,
|
|
127
|
+
file_name,
|
|
128
|
+
]
|
|
129
|
+
else:
|
|
130
|
+
# print(f'3 Yklibpy AppStore get_config_file_for_unix user={user} ')
|
|
131
|
+
config_file_name_array = [
|
|
132
|
+
str(self.home_path),
|
|
133
|
+
".config",
|
|
134
|
+
self.prog_name,
|
|
135
|
+
file_name,
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
return config_file_name_array
|
|
139
|
+
|
|
140
|
+
def get_db_file_for_unix(self, user: str | None, base_name: str, ext_name: str):
|
|
141
|
+
file_name = f"{base_name}{ext_name}"
|
|
142
|
+
if user is not None and user != "":
|
|
143
|
+
db_file_name_array = [
|
|
144
|
+
str(self.home_path),
|
|
145
|
+
".local",
|
|
146
|
+
"share",
|
|
147
|
+
self.prog_name,
|
|
148
|
+
user,
|
|
149
|
+
file_name,
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
else:
|
|
153
|
+
# print(f'4 Yklibpy AppStore get_db_file_for_unix user={user} ')
|
|
154
|
+
db_file_name_array = [
|
|
155
|
+
str(self.home_path),
|
|
156
|
+
".local",
|
|
157
|
+
"share",
|
|
158
|
+
self.prog_name,
|
|
159
|
+
file_name,
|
|
160
|
+
]
|
|
161
|
+
return db_file_name_array
|
|
162
|
+
|
|
163
|
+
def get_from_config(self, base_name: str, key: str) -> Any:
|
|
164
|
+
if self.user is not None:
|
|
165
|
+
return self.assoc["config"][base_name]["value"][self.user][key]
|
|
166
|
+
else:
|
|
167
|
+
return self.assoc["config"][base_name]["value"][key]
|
|
168
|
+
|
|
169
|
+
def output_config(self, key: str, data: dict[str, Any]) -> None:
|
|
170
|
+
# print( f'Yklibpy AppStore output_config self.user={self.user} key={key} data={data}' )
|
|
171
|
+
if self.user is None:
|
|
172
|
+
# print(f'5 Yklibpy AppStore output_config self.user={self.user} ')
|
|
173
|
+
self.assoc["config"][key]["file"].output(data)
|
|
174
|
+
else:
|
|
175
|
+
# print( f'2 Yklibpy AppStore output_config self.user={self.user}' )
|
|
176
|
+
self.assoc["config"][key]["file"][self.user].output(data)
|
|
177
|
+
|
|
178
|
+
def output_db(self, key: str, data: dict[str, Any]) -> None:
|
|
179
|
+
# print(f'6 Yklibpy AppStore output_db')
|
|
180
|
+
if self.user is None:
|
|
181
|
+
#print(f'7 self.assoc["d"b"][key]["file"]={self.assoc["db"][key]["file"]}')
|
|
182
|
+
self.assoc["db"][key]["file"].output(data)
|
|
183
|
+
else:
|
|
184
|
+
self.assoc["db"][key]["file"][self.user].output(data)
|
|
185
|
+
|
|
186
|
+
def show(self, kind: str, base_name: str) -> None:
|
|
187
|
+
if self.user is None:
|
|
188
|
+
# print(f'7 Yklibpy AppStore show user={user} ')
|
|
189
|
+
dict_x = self.assoc[kind][base_name]["value"]
|
|
190
|
+
else:
|
|
191
|
+
dict_x = self.assoc[kind][base_name]["value"][self.user]
|
|
192
|
+
|
|
193
|
+
for key in dict_x.keys():
|
|
194
|
+
print( f'key={key}' )
|
|
195
|
+
print( dict_x[key])
|
|
196
|
+
|
|
197
|
+
def show_config(self, user: str | None, base_name: str) -> None:
|
|
198
|
+
self.show(user, "config", base_name)
|
|
199
|
+
|
|
200
|
+
def show_db(self, user: str | None, base_name: str) -> None:
|
|
201
|
+
self.show(user, "db", base_name)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import json
|
|
1
2
|
from pathlib import Path
|
|
2
3
|
from typing import Any
|
|
4
|
+
|
|
3
5
|
import yaml
|
|
4
|
-
import json
|
|
5
6
|
|
|
6
7
|
from yklibpy.config.appconfig import AppConfig
|
|
7
8
|
|
|
@@ -17,14 +18,20 @@ class Storex:
|
|
|
17
18
|
def get_ext_name(cls, file_type: str) -> str:
|
|
18
19
|
return cls._file_type_dict[file_type]
|
|
19
20
|
|
|
20
|
-
def __init__(self, file_type: str, file_name_array: list[str]
|
|
21
|
-
self.file_name_array = file_name_array
|
|
21
|
+
def __init__(self, file_type: str, file_name_array: list[str]):
|
|
22
|
+
self.file_name_array = file_name_array
|
|
22
23
|
self.file_type = file_type
|
|
23
24
|
|
|
24
25
|
# file_name_arrayは完全なパス要素の配列(呼び出し元で構築済み)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
top_dir = file_name_array.pop(0)
|
|
27
|
+
top_path = Path(top_dir)
|
|
28
|
+
for file_name in file_name_array:
|
|
29
|
+
# print(f'file_name={file_name}')
|
|
30
|
+
top_path = top_path / Path(file_name)
|
|
31
|
+
|
|
32
|
+
self.file_path = top_path
|
|
33
|
+
# self.file_path = Path(**file_name_array)
|
|
34
|
+
self.store: dict[str, Any] = {}
|
|
28
35
|
|
|
29
36
|
def get_value(self, key: str) -> Any:
|
|
30
37
|
return self.store.get(key)
|
|
@@ -32,7 +32,7 @@ class App:
|
|
|
32
32
|
Scraper: Concrete scraper that knows how to parse the given site, or
|
|
33
33
|
``None`` when the mode is unsupported.
|
|
34
34
|
"""
|
|
35
|
-
print(f"mode={mode} is not supported")
|
|
35
|
+
# print(f"mode={mode} is not supported")
|
|
36
36
|
return None
|
|
37
37
|
|
|
38
38
|
def loop(self, files: List[Path], mode: str, sequence: int):
|
|
@@ -45,7 +45,7 @@ class App:
|
|
|
45
45
|
Returns:
|
|
46
46
|
dict: Mapping of link identifiers to their structured attributes.
|
|
47
47
|
"""
|
|
48
|
-
print(f"S loop files={files}")
|
|
48
|
+
# print(f"S loop files={files}")
|
|
49
49
|
assoc: dict[str, dict[str, str]] = {}
|
|
50
50
|
for file in files:
|
|
51
51
|
scraper: Scraper | None = self.create_scraper(mode, sequence)
|
|
@@ -56,13 +56,15 @@ class App:
|
|
|
56
56
|
len_extracted_links_assoc = len(extracted_links_assoc)
|
|
57
57
|
if len_extracted_links_assoc > 0:
|
|
58
58
|
len_assoc = len(assoc)
|
|
59
|
-
print(f"0 len_assoc={len_assoc}")
|
|
59
|
+
# print(f"0 len_assoc={len_assoc}")
|
|
60
60
|
assoc.update(extracted_links_assoc)
|
|
61
|
-
print(f"1 len_assoc={len(assoc)}")
|
|
61
|
+
# print(f"1 len_assoc={len(assoc)}")
|
|
62
62
|
else:
|
|
63
|
-
print(f"3 len_extracted_links_assoc={len_extracted_links_assoc}")
|
|
63
|
+
# print(f"3 len_extracted_links_assoc={len_extracted_links_assoc}")
|
|
64
|
+
pass
|
|
64
65
|
else:
|
|
65
|
-
print(f"4 extracted_links_assoc={extracted_links_assoc}")
|
|
66
|
+
# print(f"4 extracted_links_assoc={extracted_links_assoc}")
|
|
67
|
+
pass
|
|
66
68
|
return assoc
|
|
67
69
|
|
|
68
70
|
def run(self, env: Env):
|
|
@@ -78,7 +80,7 @@ class App:
|
|
|
78
80
|
sequence = env.sequence
|
|
79
81
|
message = f"path_array={path_array} sequence={sequence}"
|
|
80
82
|
# raise Exception(message)
|
|
81
|
-
print(message)
|
|
83
|
+
# print(message)
|
|
82
84
|
|
|
83
85
|
mode = env.mode()
|
|
84
86
|
|
|
@@ -36,7 +36,7 @@ class HtmlOp:
|
|
|
36
36
|
list = child.find_all("div")
|
|
37
37
|
|
|
38
38
|
for div_tag in list:
|
|
39
|
-
print(f"get_anchor_under_div div_tag: {div_tag}")
|
|
39
|
+
# print(f"get_anchor_under_div div_tag: {div_tag}")
|
|
40
40
|
anchor_tag_info_array = HtmlOp.get_anchor_all(div_tag)
|
|
41
41
|
for anchor_tag_info in anchor_tag_info_array:
|
|
42
42
|
cls.print_tag_info(anchor_tag_info)
|
|
@@ -33,8 +33,8 @@ class Preparex:
|
|
|
33
33
|
re_file_extname = re.compile(file_extname_x)
|
|
34
34
|
pattern = "*"
|
|
35
35
|
# pattern = ".yaml"
|
|
36
|
-
print(f"file_extname={file_extname}")
|
|
37
|
-
print(f"self.top_path={self.top_path}")
|
|
36
|
+
# print(f"file_extname={file_extname}")
|
|
37
|
+
# print(f"self.top_path={self.top_path}")
|
|
38
38
|
target_type: Literal["file", "dir", "both"] = "file"
|
|
39
39
|
# target_type = "dir"
|
|
40
40
|
# target_type = "both"
|
|
@@ -55,11 +55,11 @@ class Preparex:
|
|
|
55
55
|
ul.append(left)
|
|
56
56
|
right = array[1]
|
|
57
57
|
|
|
58
|
-
print(f"stem={stem}")
|
|
59
|
-
print(f"left={left}")
|
|
60
|
-
print(f"right={right}")
|
|
58
|
+
# print(f"stem={stem}")
|
|
59
|
+
# print(f"left={left}")
|
|
60
|
+
# print(f"right={right}")
|
|
61
61
|
|
|
62
|
-
print(ul)
|
|
62
|
+
# print(ul)
|
|
63
63
|
|
|
64
64
|
def list_files_containing(self, path: Path, search_string: str) -> List[Path]:
|
|
65
65
|
"""
|
|
@@ -86,25 +86,25 @@ class Preparex:
|
|
|
86
86
|
def list_files(self, path: Path, name: str) -> List[Path]:
|
|
87
87
|
files = self.list_files_containing(path, name)
|
|
88
88
|
for file in files:
|
|
89
|
-
print(file)
|
|
90
|
-
print(file.name)
|
|
89
|
+
# print(file)
|
|
90
|
+
# print(file.name)
|
|
91
91
|
return files
|
|
92
92
|
|
|
93
93
|
def list_htmlparser_files(self, name: str) -> List[Path]:
|
|
94
94
|
files = self.list_files_containing(self.htmlparser_path, name)
|
|
95
95
|
for file in files:
|
|
96
|
-
print(file)
|
|
97
|
-
print(file.name)
|
|
98
|
-
print(file.stem)
|
|
99
|
-
print(file.suffix)
|
|
100
|
-
print(file.parent)
|
|
96
|
+
# print(file)
|
|
97
|
+
# print(file.name)
|
|
98
|
+
# print(file.stem)
|
|
99
|
+
# print(file.suffix)
|
|
100
|
+
# print(file.parent)
|
|
101
101
|
return files
|
|
102
102
|
|
|
103
103
|
def list_bat1_files(self, name: str) -> List[Path]:
|
|
104
104
|
files = self.list_files_containing(self.bat1_path, name)
|
|
105
105
|
for file in files:
|
|
106
|
-
print(file)
|
|
107
|
-
print(file.name)
|
|
106
|
+
# print(file)
|
|
107
|
+
# print(file.name)
|
|
108
108
|
return files
|
|
109
109
|
|
|
110
110
|
def list_utility_files(self, name: str, suffix: str) -> List[Path]:
|
|
@@ -156,17 +156,19 @@ class Tomlop:
|
|
|
156
156
|
def read_toml_external(self, file_path):
|
|
157
157
|
try:
|
|
158
158
|
with open(file_path, "r", encoding="utf-8") as f:
|
|
159
|
-
print(f"file_path = {file_path}")
|
|
159
|
+
# print(f"file_path = {file_path}")
|
|
160
160
|
try:
|
|
161
161
|
self.data = toml.load(f)
|
|
162
162
|
except Exception as e:
|
|
163
163
|
print(f"エラー: {e}")
|
|
164
164
|
return None
|
|
165
|
-
|
|
166
|
-
|
|
165
|
+
'''
|
|
166
|
+
print(f'data={self.data}')
|
|
167
|
+
print(f'self.data["project"]={self.data["project"]}')
|
|
167
168
|
print(
|
|
168
169
|
f'self.data["project"]["authors"]={self.data["project"]["authors"]}'
|
|
169
170
|
)
|
|
171
|
+
'''
|
|
170
172
|
return self.data
|
|
171
173
|
except FileNotFoundError:
|
|
172
174
|
print(f"ファイルが見つかりません: {file_path}")
|
|
@@ -194,13 +196,15 @@ class Tomlop:
|
|
|
194
196
|
return False
|
|
195
197
|
|
|
196
198
|
def load_toml(self, ref_file):
|
|
197
|
-
print(f"ref_file={ref_file}")
|
|
199
|
+
# print(f"ref_file={ref_file}")
|
|
198
200
|
ref = None
|
|
199
201
|
if ref_file:
|
|
200
202
|
ref = self.read_toml_external(ref_file)
|
|
203
|
+
'''
|
|
201
204
|
if ref is not None:
|
|
202
205
|
print(ref.keys())
|
|
203
|
-
|
|
206
|
+
rint("--------------------------------")
|
|
207
|
+
'''
|
|
204
208
|
return ref
|
|
205
209
|
|
|
206
210
|
def load_file(self, file_path):
|
|
@@ -221,11 +225,11 @@ class Tomlop:
|
|
|
221
225
|
|
|
222
226
|
new_config = self.merge_dict(config, ref)
|
|
223
227
|
result = self.compare_dict(new_config, ref)
|
|
224
|
-
print(f"# result={result}")
|
|
225
|
-
print(f"# new_config={new_config}")
|
|
228
|
+
# print(f"# result={result}")
|
|
229
|
+
# print(f"# new_config={new_config}")
|
|
226
230
|
diff_result = self.diff_dict(new_config, ref)
|
|
227
|
-
print("# diff")
|
|
228
|
-
print(f"diff_result={diff_result}")
|
|
231
|
+
# print("# diff")
|
|
232
|
+
# print(f"diff_result={diff_result}")
|
|
229
233
|
self.write_toml_external("new_pyproject.toml", new_config)
|
|
230
234
|
|
|
231
235
|
def store_yaml(self, file_path, data):
|
|
@@ -299,9 +303,9 @@ class Tomlop:
|
|
|
299
303
|
input_path = Path(sys.argv[1]) if len(sys.argv) > 1 else None
|
|
300
304
|
if input_path is not None:
|
|
301
305
|
data: dict[str, Any] = UtilYaml.load_yaml(input_path)
|
|
302
|
-
print(f"data={data}")
|
|
306
|
+
# print(f"data={data}")
|
|
303
307
|
new_file_path = input_path.with_suffix(".toml")
|
|
304
|
-
print(f"new_file_path={new_file_path}")
|
|
308
|
+
# print(f"new_file_path={new_file_path}")
|
|
305
309
|
|
|
306
310
|
|
|
307
311
|
def zmain():
|
|
@@ -1,120 +0,0 @@
|
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|