yklibpy 0.1.0__py3-none-any.whl
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/__init__.py +17 -0
- yklibpy/common/__init__.py +15 -0
- yklibpy/common/convert_yaml_strip_tags.py +102 -0
- yklibpy/common/env.py +109 -0
- yklibpy/common/info.py +24 -0
- yklibpy/common/util.py +419 -0
- yklibpy/db/__init__.py +27 -0
- yklibpy/db/db_base.py +6 -0
- yklibpy/db/db_yaml.py +61 -0
- yklibpy/htmlparser/__init__.py +37 -0
- yklibpy/htmlparser/amazon.py +3 -0
- yklibpy/htmlparser/amazonsavedcartscraper.py +106 -0
- yklibpy/htmlparser/app.py +101 -0
- yklibpy/htmlparser/ascraper.py +77 -0
- yklibpy/htmlparser/configprepare.py +29 -0
- yklibpy/htmlparser/fanzadoujinpurchasedscraper.py +80 -0
- yklibpy/htmlparser/fanzadoujinscraper.py +235 -0
- yklibpy/htmlparser/h3scraper.py +68 -0
- yklibpy/htmlparser/htmlop.py +107 -0
- yklibpy/htmlparser/kuscraper.py +68 -0
- yklibpy/htmlparser/preparex.py +152 -0
- yklibpy/htmlparser/progress.py +36 -0
- yklibpy/htmlparser/py.typed +0 -0
- yklibpy/htmlparser/scraper.py +181 -0
- yklibpy/htmlparser/udemyscraper.py +224 -0
- yklibpy/tomlop/__init__.py +17 -0
- yklibpy/tomlop/tomlop.py +374 -0
- yklibpy-0.1.0.dist-info/METADATA +20 -0
- yklibpy-0.1.0.dist-info/RECORD +31 -0
- yklibpy-0.1.0.dist-info/WHEEL +4 -0
- yklibpy-0.1.0.dist-info/entry_points.txt +10 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
from urllib.parse import urlparse
|
|
3
|
+
|
|
4
|
+
from ..common.info import Info
|
|
5
|
+
from .scraper import Scraper
|
|
6
|
+
|
|
7
|
+
import traceback
|
|
8
|
+
from ..common.util import Util
|
|
9
|
+
from .htmlop import HtmlOp
|
|
10
|
+
|
|
11
|
+
class FanzaDoujinScraper(Scraper):
|
|
12
|
+
class WorkInfo:
|
|
13
|
+
def __init__(self, target: str, url: str, title: str, maker_url: str, maker_text: str, creator_url: str, creator_text: str, price_old: str, price_real: str):
|
|
14
|
+
self.target = target
|
|
15
|
+
self.title = title
|
|
16
|
+
self.maker_text = maker_text
|
|
17
|
+
self.creator_text = creator_text
|
|
18
|
+
self.price_old = price_old
|
|
19
|
+
self.price_real = price_real
|
|
20
|
+
|
|
21
|
+
result_array = Util.isValidUrls([url, maker_url, creator_url])
|
|
22
|
+
if result_array[0].success:
|
|
23
|
+
self.url = url
|
|
24
|
+
else:
|
|
25
|
+
self.url = None
|
|
26
|
+
|
|
27
|
+
if result_array[1].success:
|
|
28
|
+
self.maker_url = maker_url
|
|
29
|
+
else:
|
|
30
|
+
self.url = None
|
|
31
|
+
|
|
32
|
+
if result_array[2].success:
|
|
33
|
+
self.creator_url = creator_url
|
|
34
|
+
else:
|
|
35
|
+
self.creator_url = None
|
|
36
|
+
|
|
37
|
+
def to_assoc(self):
|
|
38
|
+
return {
|
|
39
|
+
"target": self.target,
|
|
40
|
+
"url": self.url,
|
|
41
|
+
"title": self.title,
|
|
42
|
+
"maker_url": self.maker_url,
|
|
43
|
+
"maker_text": self.maker_text,
|
|
44
|
+
"creator_url": self.creator_url,
|
|
45
|
+
"creator_text": self.creator_text,
|
|
46
|
+
"price_old": self.price_old,
|
|
47
|
+
"price_real": self.price_real
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
def __init__(self):
|
|
51
|
+
super().__init__()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_anchor_under_p(self, child, cond = None):
|
|
55
|
+
# div basket-txtContent
|
|
56
|
+
# b basket-name
|
|
57
|
+
# p basket-circle
|
|
58
|
+
append_count = 0
|
|
59
|
+
no_append_count = 0
|
|
60
|
+
if cond is None:
|
|
61
|
+
list = child.find_all("p")
|
|
62
|
+
else:
|
|
63
|
+
list = child.find_all("p", cond)
|
|
64
|
+
# print(f"get_anchor_under_p list={list}")
|
|
65
|
+
# print(f"child={child}")
|
|
66
|
+
|
|
67
|
+
assoc_array = [ HtmlOp.get_anchor_all(p_tag) for p_tag in list ]
|
|
68
|
+
|
|
69
|
+
return assoc_array
|
|
70
|
+
|
|
71
|
+
def get_work_maker_and_creator(self, div_tag):
|
|
72
|
+
cond = {"class": "basket-circle"}
|
|
73
|
+
assoc_array_p = self.get_anchor_under_p(div_tag, cond)
|
|
74
|
+
assoc_p_flat = list(Util.flatten_gen(assoc_array_p))
|
|
75
|
+
|
|
76
|
+
maker = None
|
|
77
|
+
creator = None
|
|
78
|
+
for as_p in assoc_p_flat:
|
|
79
|
+
url = as_p.anchor.href
|
|
80
|
+
text = as_p.anchor.text
|
|
81
|
+
result_array = Util.isValidUrls([url])
|
|
82
|
+
if result_array[0].success:
|
|
83
|
+
array = result_array[0].parsed.path.split('/')
|
|
84
|
+
if "article=maker" in array:
|
|
85
|
+
maker = as_p
|
|
86
|
+
elif "article=creator" in array:
|
|
87
|
+
creator = as_p
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError(f"URL '{url}' is not a valid URI: missing maker or creator")
|
|
90
|
+
|
|
91
|
+
return {"maker": maker, "creator": creator}
|
|
92
|
+
|
|
93
|
+
def get_price_under_p(self, div_tag):
|
|
94
|
+
cond = {"class": "c_txt_price"}
|
|
95
|
+
|
|
96
|
+
p_tag = div_tag.find("p", cond)
|
|
97
|
+
if p_tag is None:
|
|
98
|
+
return None
|
|
99
|
+
cond_span = {"class": "price-old"}
|
|
100
|
+
|
|
101
|
+
price_old = None
|
|
102
|
+
span_text = None
|
|
103
|
+
span_tag = p_tag.find("span", cond_span)
|
|
104
|
+
if span_tag is None:
|
|
105
|
+
span_tag = p_tag.find("span")
|
|
106
|
+
if span_tag:
|
|
107
|
+
span_text = span_tag.text
|
|
108
|
+
else:
|
|
109
|
+
span_text = span_tag.text
|
|
110
|
+
price_old = HtmlOp.Tagx(span_tag, "price-old")
|
|
111
|
+
price_old.set_option(span_text)
|
|
112
|
+
|
|
113
|
+
strong_tag = p_tag.find("strong")
|
|
114
|
+
strong_text = strong_tag.text
|
|
115
|
+
price_real = HtmlOp.Tagx(strong_tag, "price-real")
|
|
116
|
+
price_real.set_option(strong_text)
|
|
117
|
+
price_info = HtmlOp.PriceInfo(price_old, price_real)
|
|
118
|
+
if price_old is None and price_real is None:
|
|
119
|
+
raise ValueError(f"price_old and price_real are None")
|
|
120
|
+
if price_real is None:
|
|
121
|
+
raise ValueError(f"price_real is None")
|
|
122
|
+
return price_info
|
|
123
|
+
|
|
124
|
+
def get_work_name(self, div_tag):
|
|
125
|
+
work_name = None
|
|
126
|
+
cond = {"class": "basket-name"}
|
|
127
|
+
assoc_array_b = HtmlOp.get_anchor_under_b(div_tag, cond)
|
|
128
|
+
assoc_b_flat = list(Util.flatten_gen(assoc_array_b))
|
|
129
|
+
if len(assoc_b_flat) != 1:
|
|
130
|
+
cond_result = {"class": "basket-resultTxt"}
|
|
131
|
+
array = div_tag.find("p", cond_result)
|
|
132
|
+
if array is not None:
|
|
133
|
+
len_array = list(Util.flatten_gen(array))
|
|
134
|
+
if len(array) == 1:
|
|
135
|
+
return work_name
|
|
136
|
+
else:
|
|
137
|
+
raise ValueError(f"Expected 1 anchor, got {len(len_array)}")
|
|
138
|
+
else:
|
|
139
|
+
as_b = assoc_b_flat[0]
|
|
140
|
+
url = as_b.anchor.href
|
|
141
|
+
text = as_b.anchor.text
|
|
142
|
+
work_name = as_b
|
|
143
|
+
|
|
144
|
+
return work_name
|
|
145
|
+
|
|
146
|
+
def get_and_register_work_info(self, div_tag, target):
|
|
147
|
+
self.target = target
|
|
148
|
+
|
|
149
|
+
creator_url = ""
|
|
150
|
+
creator_text = ""
|
|
151
|
+
maker_url = ""
|
|
152
|
+
maker_text = ""
|
|
153
|
+
|
|
154
|
+
price_info = self.get_price_under_p(div_tag)
|
|
155
|
+
if price_info is None:
|
|
156
|
+
return
|
|
157
|
+
price_old = price_info.get_price_old()
|
|
158
|
+
price_real = price_info.get_price_real()
|
|
159
|
+
|
|
160
|
+
work_name = self.get_work_name(div_tag)
|
|
161
|
+
if work_name is None:
|
|
162
|
+
return
|
|
163
|
+
url = work_name.anchor.href
|
|
164
|
+
title = work_name.anchor.text
|
|
165
|
+
result = Util.isValidUrls([url])
|
|
166
|
+
if not result:
|
|
167
|
+
raise ValueError(f"URL '{url}' is not a valid URI")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
assoc = self.get_work_maker_and_creator(div_tag)
|
|
171
|
+
maker = assoc["maker"]
|
|
172
|
+
creator = assoc["creator"]
|
|
173
|
+
maker_url = maker.anchor.href
|
|
174
|
+
maker_text = maker.anchor.text
|
|
175
|
+
if creator is not None:
|
|
176
|
+
creator_url = creator.anchor.href
|
|
177
|
+
creator_text = creator.anchor.text
|
|
178
|
+
else:
|
|
179
|
+
creator_url = ""
|
|
180
|
+
creator_text = ""
|
|
181
|
+
|
|
182
|
+
work_info = self.WorkInfo(target=target, url=url, title=title, maker_url=maker_url, maker_text=maker_text, creator_url=creator_url, creator_text=creator_text, price_old=price_old, price_real=price_real)
|
|
183
|
+
result = self.add_list_and_assoc(work_info)
|
|
184
|
+
return result
|
|
185
|
+
|
|
186
|
+
def add_list_and_assoc(self, work_info: WorkInfo) -> bool:
|
|
187
|
+
result = False
|
|
188
|
+
if work_info.url not in self.links_assoc.keys():
|
|
189
|
+
cid = Util.extract_cid(work_info.url)
|
|
190
|
+
self.links_assoc[cid] = work_info.to_assoc()
|
|
191
|
+
self.links_list.append(work_info)
|
|
192
|
+
result = True
|
|
193
|
+
else:
|
|
194
|
+
pass
|
|
195
|
+
|
|
196
|
+
return result
|
|
197
|
+
|
|
198
|
+
def scrape(self, info: Info) -> List[Dict[str, str]]:
|
|
199
|
+
print("FanzaDoujin scrape")
|
|
200
|
+
soup = info.soup
|
|
201
|
+
append_count = 0
|
|
202
|
+
no_append_count = 0
|
|
203
|
+
class_str = "c_hdg_normalWeak"
|
|
204
|
+
# div_tagの子要素を列挙して表示
|
|
205
|
+
print("--- 子要素の列挙 ---")
|
|
206
|
+
# for div_tag in soup.find_all("div", {"id": "basket-itemContent"}):
|
|
207
|
+
target = None
|
|
208
|
+
for section_tag in soup.find_all("section"):
|
|
209
|
+
h2_tag = section_tag.find("h2", {"class": class_str})
|
|
210
|
+
if h2_tag is None:
|
|
211
|
+
raise ValueError(f"h2_tag is None")
|
|
212
|
+
|
|
213
|
+
h2_text = h2_tag.text
|
|
214
|
+
if h2_text == "バスケット":
|
|
215
|
+
target = "basket"
|
|
216
|
+
elif h2_text == "「お気に入り」に入っている商品":
|
|
217
|
+
target = "bookmark"
|
|
218
|
+
else:
|
|
219
|
+
raise ValueError(f"h2_tag.text is not 'バスケット' or '「お気に入り」に入っている商品'")
|
|
220
|
+
|
|
221
|
+
for div_tag in section_tag.find_all("div", {"class": "basket-itemContent"}):
|
|
222
|
+
result = self.get_and_register_work_info(div_tag, target)
|
|
223
|
+
|
|
224
|
+
if result:
|
|
225
|
+
append_count += 1
|
|
226
|
+
else:
|
|
227
|
+
no_append_count += 1
|
|
228
|
+
|
|
229
|
+
print("--- 子要素の列挙終了 ---")
|
|
230
|
+
|
|
231
|
+
info.append_count = append_count
|
|
232
|
+
info.no_append_count = no_append_count
|
|
233
|
+
self.append_count += append_count
|
|
234
|
+
self.no_append_count += no_append_count
|
|
235
|
+
return self.links_list
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
from ..common.info import Info
|
|
4
|
+
from .udemyscraper import UdemyScraper
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class H3Scraper(UdemyScraper):
|
|
8
|
+
def __init__(self):
|
|
9
|
+
super().__init__()
|
|
10
|
+
|
|
11
|
+
def scrape(self, info: Info) -> List[Dict[str, str]]:
|
|
12
|
+
print("h3scraper scrape")
|
|
13
|
+
soup = info.soup
|
|
14
|
+
append_count = 0
|
|
15
|
+
no_append_count = 0
|
|
16
|
+
"""h3では部分的にしか取得できない"""
|
|
17
|
+
|
|
18
|
+
"""h3の処理"""
|
|
19
|
+
for h3_tag in soup.find_all("h3"):
|
|
20
|
+
print(f"h3_tag={h3_tag}")
|
|
21
|
+
"""
|
|
22
|
+
# h3タグの子要素であるa要素を取得
|
|
23
|
+
a_tag = h3_tag.find('a')
|
|
24
|
+
if a_tag is None:
|
|
25
|
+
continue
|
|
26
|
+
url = a_tag.get('href', '#')
|
|
27
|
+
text = a_tag.get_text(strip=True)
|
|
28
|
+
|
|
29
|
+
# Extract course_id from URL parameters
|
|
30
|
+
course_id = self.get_course_id_from_url(url)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# h3タグの子要素であるdiv要素のうち、属性data-purposeの値が"safely-set-inner-html:course-card:visible-instructors"であるものを取得
|
|
34
|
+
child_div = h3_tag.find("div", {"data-purpose": "safely-set-inner-html:course-card:visible-instructors"})
|
|
35
|
+
if child_div is None:
|
|
36
|
+
raise ValueError("child_div is None")
|
|
37
|
+
|
|
38
|
+
# child_divのすべての階層のテキストを取り出して、変数instructorsに代入
|
|
39
|
+
instructors = ["_0_"]
|
|
40
|
+
|
|
41
|
+
instructors = child_div.get_text(strip=True)
|
|
42
|
+
print(f"#### instructors1={instructors}")
|
|
43
|
+
progress = self.get_progress(child_div)
|
|
44
|
+
|
|
45
|
+
# TODO: url, text, course_idを取得
|
|
46
|
+
url = "#"
|
|
47
|
+
text = "#"
|
|
48
|
+
course_id = "#"
|
|
49
|
+
|
|
50
|
+
result = self.add_list_and_assoc(
|
|
51
|
+
url=url, text=text, course_id=course_id, instructors=instructors, progress=progress
|
|
52
|
+
)
|
|
53
|
+
if result:
|
|
54
|
+
append_count += 1
|
|
55
|
+
else:
|
|
56
|
+
no_append_count += 1
|
|
57
|
+
|
|
58
|
+
info.append_count = append_count
|
|
59
|
+
info.no_append_count = no_append_count
|
|
60
|
+
self.append_count += append_count
|
|
61
|
+
self.no_append_count += no_append_count
|
|
62
|
+
|
|
63
|
+
return self.links_list
|
|
64
|
+
|
|
65
|
+
def _extract_links_from_info(self, info: Info) -> List[Dict[str, str]]:
|
|
66
|
+
super()._extract_links_from_info(info)
|
|
67
|
+
links_list = self.scrape(info)
|
|
68
|
+
return links_list
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from bs4 import BeautifulSoup
|
|
2
|
+
from bs4.element import Tag
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
class HtmlOp:
|
|
6
|
+
class Tagx:
|
|
7
|
+
def __init__(self, tag: Tag, namex: str):
|
|
8
|
+
self.tag = tag
|
|
9
|
+
self.strx = str(tag)
|
|
10
|
+
self.type = type(tag)
|
|
11
|
+
self.mes_type = f" type({namex}): { str(type(namex)) }"
|
|
12
|
+
if hasattr(tag, 'get_text'):
|
|
13
|
+
self.text = tag.get_text(strip=True)
|
|
14
|
+
self.mes_text = f" {namex}_text: {self.text}"
|
|
15
|
+
else:
|
|
16
|
+
self.mes_text = f" {namex}_text: [Nothing]"
|
|
17
|
+
|
|
18
|
+
if hasattr(tag, 'name'):
|
|
19
|
+
self.mes_name = f" {namex}.name: { tag.name }"
|
|
20
|
+
# print()
|
|
21
|
+
else:
|
|
22
|
+
self.mes_name = f" {namex}.name: [Nothing]"
|
|
23
|
+
def set_option(self, option):
|
|
24
|
+
self.option = option
|
|
25
|
+
def get_option(self):
|
|
26
|
+
return self.option
|
|
27
|
+
|
|
28
|
+
class AnchorTagx(Tagx):
|
|
29
|
+
def __init__(self, anchor_tag):
|
|
30
|
+
super().__init__(anchor_tag, "anchor")
|
|
31
|
+
self.href = self.tag.get("href", "")
|
|
32
|
+
self.text = self.tag.get_text(strip=True)
|
|
33
|
+
self.mes_href = f" href: {self.href}"
|
|
34
|
+
self.mes_text = f" text: {self.text}"
|
|
35
|
+
def show(self):
|
|
36
|
+
return "\n".join([self.href, self.text])
|
|
37
|
+
|
|
38
|
+
class AnchorTagInfo:
|
|
39
|
+
def __init__(self, anchor_tag):
|
|
40
|
+
self.anchor = HtmlOp.AnchorTagx(anchor_tag)
|
|
41
|
+
|
|
42
|
+
def setup(self):
|
|
43
|
+
# print()
|
|
44
|
+
self.next_sibling = Tagx(self.anchor.tag.next_sibling, "next_sibling")
|
|
45
|
+
self.parent = Tagx(self.anchor.tag.next_sibling, "parent")
|
|
46
|
+
self.parent_parent = Tagx(self.anchor.tag.parent.parent, "parent.parent")
|
|
47
|
+
|
|
48
|
+
class PriceInfo:
|
|
49
|
+
def __init__(self, price_old, price_real):
|
|
50
|
+
self.price_old = price_old
|
|
51
|
+
self.price_real = price_real
|
|
52
|
+
def get_price_old(self):
|
|
53
|
+
if self.price_old is None:
|
|
54
|
+
return None
|
|
55
|
+
return self.price_old.get_option()
|
|
56
|
+
def get_price_real(self):
|
|
57
|
+
if self.price_real is None:
|
|
58
|
+
return None
|
|
59
|
+
return self.price_real.get_option()
|
|
60
|
+
|
|
61
|
+
@classmethod
|
|
62
|
+
def get_anchor_under_b(cls, child, cond = None):
|
|
63
|
+
if cond is None:
|
|
64
|
+
list = child.find_all("b")
|
|
65
|
+
else:
|
|
66
|
+
list = child.find_all("b", cond)
|
|
67
|
+
assoc_array = [ cls.get_anchor_all(b_tag) for b_tag in list ]
|
|
68
|
+
|
|
69
|
+
return assoc_array
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def get_anchor_all(cls, child):
|
|
73
|
+
return [cls.get_anchor_tag_info(anchor_tag) for anchor_tag in child.find_all("a")]
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def get_anchor_tag_info(cls, anchor_tag):
|
|
77
|
+
if anchor_tag is None:
|
|
78
|
+
return None
|
|
79
|
+
|
|
80
|
+
# print('----')
|
|
81
|
+
a_tag_info = cls.AnchorTagInfo(anchor_tag)
|
|
82
|
+
|
|
83
|
+
return a_tag_info
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def get_anchor_under_div(cls, child, cond = None):
|
|
87
|
+
if cond is None:
|
|
88
|
+
list = child.find_all("div", cond)
|
|
89
|
+
else:
|
|
90
|
+
list = child.find_all("div")
|
|
91
|
+
|
|
92
|
+
for div_tag in list:
|
|
93
|
+
print(f"get_anchor_under_div div_tag: {div_tag}")
|
|
94
|
+
anchor_tag_info_array = HtmlOp.get_anchor_all(div_tag)
|
|
95
|
+
for anchor_tag_info in anchor_tag_info_array:
|
|
96
|
+
cls.print_tag_info(anchor_tag_info)
|
|
97
|
+
|
|
98
|
+
'''
|
|
99
|
+
@classmethod
|
|
100
|
+
def print_tag_info(cls, assoc):
|
|
101
|
+
tag = assoc["tag"]
|
|
102
|
+
print(tag)
|
|
103
|
+
|
|
104
|
+
mes_array = assoc["mes_array"]
|
|
105
|
+
mes = "\n".join(mes_array)
|
|
106
|
+
print(mes)
|
|
107
|
+
'''
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
from ..common.info import Info
|
|
4
|
+
from .scraper import Scraper
|
|
5
|
+
from ..common.util import Util
|
|
6
|
+
|
|
7
|
+
class KUScraper(Scraper):
|
|
8
|
+
class WorkInfo:
|
|
9
|
+
def __init__(self, url: str, title: str):
|
|
10
|
+
result = Util.isValidUrls( [url])
|
|
11
|
+
if result:
|
|
12
|
+
self.url = url
|
|
13
|
+
self.title = title
|
|
14
|
+
else:
|
|
15
|
+
self.url = None
|
|
16
|
+
self.title = None
|
|
17
|
+
|
|
18
|
+
def to_assoc(self):
|
|
19
|
+
return {
|
|
20
|
+
"url": self.url,
|
|
21
|
+
"titlet": self.title,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def __init__(self):
|
|
25
|
+
super().__init__()
|
|
26
|
+
|
|
27
|
+
def scrape(self, info: Info) -> List[Dict[str, str]]:
|
|
28
|
+
# <div id="itemsList" class="a-section a-spacing-top-large">
|
|
29
|
+
# <ul id="listContainer" class="a-unordered-list a-nostyle a-vertical" role="list">
|
|
30
|
+
|
|
31
|
+
soup = info.soup
|
|
32
|
+
"""aの処理"""
|
|
33
|
+
for div_tag in soup.find_all("div", {"id":"itemsList"}):
|
|
34
|
+
for a_tag in div_tag.find_all("a"):
|
|
35
|
+
if a_tag.get("class") != ["a-link-normal"]:
|
|
36
|
+
continue
|
|
37
|
+
url = a_tag.get("href", "#")
|
|
38
|
+
img_tag = a_tag.find("img")
|
|
39
|
+
if img_tag:
|
|
40
|
+
title = img_tag.get("alt", "")
|
|
41
|
+
else:
|
|
42
|
+
title = a_tag.get_text(strip=True)
|
|
43
|
+
# print(f"text={text}")
|
|
44
|
+
work_info = self.WorkInfo(url=url, title=title)
|
|
45
|
+
self.add_list_and_assoc(work_info)
|
|
46
|
+
return self.links_list
|
|
47
|
+
|
|
48
|
+
def add_list_and_assoc(
|
|
49
|
+
self, work_info: WorkInfo
|
|
50
|
+
) -> bool:
|
|
51
|
+
"""Insert a new record if the ``course_id`` has not been seen.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
url (str): Course URL.
|
|
55
|
+
text (str): Anchor text/label.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
bool: ``True`` when the record was added, else ``False``.
|
|
59
|
+
"""
|
|
60
|
+
result = False
|
|
61
|
+
if work_info.url not in self.links_assoc.keys():
|
|
62
|
+
self.links_assoc[work_info.url] = work_info.to_assoc()
|
|
63
|
+
self.links_list.append(work_info)
|
|
64
|
+
result = True
|
|
65
|
+
else:
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
return result
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import re
|
|
3
|
+
from ..common.util import Util
|
|
4
|
+
from .configprepare import ConfigPrepare
|
|
5
|
+
|
|
6
|
+
class Preparex:
|
|
7
|
+
def __init__(self, top_dir, category, config_parent_dir, assoc):
|
|
8
|
+
config = ConfigPrepare(config_parent_dir, assoc)
|
|
9
|
+
self.parts = config.get_utility_category()
|
|
10
|
+
self.top_path = Path(top_dir)
|
|
11
|
+
self.bat1_path = self.top_path / config.get_command_dir()
|
|
12
|
+
self.htmlparser_path = self.top_path / category
|
|
13
|
+
|
|
14
|
+
self.htmlparser_path.mkdir(parents=True, exist_ok=True)
|
|
15
|
+
|
|
16
|
+
self.bat1_path.mkdir(parents=True, exist_ok=True)
|
|
17
|
+
self.htmlparser_path.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
htmlparser_path = self.top_path / category
|
|
20
|
+
ul = Util.UniqueList()
|
|
21
|
+
file_extname = config.get_category_config_file_extname()
|
|
22
|
+
# file_extname_x = rf"file_extname{'$'}"
|
|
23
|
+
# re_file_extname = re.compile(re.escape(file_extname_x))
|
|
24
|
+
file_extname_escape = re.escape(file_extname)
|
|
25
|
+
file_extname_x = file_extname_escape + '$'
|
|
26
|
+
# OK file_extname_r = r"\.yaml$"
|
|
27
|
+
# re_file_extname = re.compile(re.escape(file_extname_r))
|
|
28
|
+
# re_file_extname = re.compile(file_extname_r)
|
|
29
|
+
re_file_extname = re.compile(file_extname_x)
|
|
30
|
+
pattern = "*"
|
|
31
|
+
# pattern = ".yaml"
|
|
32
|
+
print(f'file_extname={file_extname}')
|
|
33
|
+
print(f'self.top_path={self.top_path}')
|
|
34
|
+
target_type = "file"
|
|
35
|
+
# target_type = "dir"
|
|
36
|
+
# target_type = "both"
|
|
37
|
+
for path in Util.find_paths(self.top_path, pattern, target_type):
|
|
38
|
+
# print(f'path={path}')
|
|
39
|
+
name = str(path.name)
|
|
40
|
+
# print(f'0 name={name}')
|
|
41
|
+
if not re_file_extname.search(name):
|
|
42
|
+
continue
|
|
43
|
+
# print(f'1 name={name}')
|
|
44
|
+
stem = path.stem
|
|
45
|
+
|
|
46
|
+
array = stem.split('-')
|
|
47
|
+
size = len(array)
|
|
48
|
+
# print(f'size={size}')
|
|
49
|
+
if size == 2:
|
|
50
|
+
left = array[0]
|
|
51
|
+
ul.append(left)
|
|
52
|
+
right = array[1]
|
|
53
|
+
|
|
54
|
+
print(f'stem={stem}')
|
|
55
|
+
print(f'left={left}')
|
|
56
|
+
print(f'right={right}')
|
|
57
|
+
|
|
58
|
+
print(ul)
|
|
59
|
+
'''
|
|
60
|
+
print(top_config.get_command())
|
|
61
|
+
print(top_config.get_category())
|
|
62
|
+
print(top_config.get_htmlparser())
|
|
63
|
+
print(top_config.get_utility_category())
|
|
64
|
+
print(top_config.get_utility_root())
|
|
65
|
+
'''
|
|
66
|
+
'''
|
|
67
|
+
if parent_path.exists() and parent_path.is_dir():
|
|
68
|
+
list = parent_path.rglob('*.bat')
|
|
69
|
+
# list = parent_path.glob('*.bat')
|
|
70
|
+
# list = parent_path.glob('*.yaml')
|
|
71
|
+
# list = parent_path.rglob('*.yaml')
|
|
72
|
+
# list = parent_path.rglob('*.json')
|
|
73
|
+
for item in list:
|
|
74
|
+
print(f'item={item.resolve()}')
|
|
75
|
+
'''
|
|
76
|
+
|
|
77
|
+
def list_files_containing(self, path, search_string):
|
|
78
|
+
"""
|
|
79
|
+
指定パス直下に存在するファイルのうち、ファイル名が指定文字列を含むものをすべて列挙する
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
path: 検索対象のパス(Pathオブジェクトまたは文字列)
|
|
83
|
+
search_string: ファイル名に含まれる文字列
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
条件に一致するファイルのPathオブジェクトのリスト
|
|
87
|
+
"""
|
|
88
|
+
target_path = Path(path) if isinstance(path, str) else path
|
|
89
|
+
if not target_path.exists() or not target_path.is_dir():
|
|
90
|
+
return []
|
|
91
|
+
|
|
92
|
+
matching_files = []
|
|
93
|
+
for file_path in target_path.iterdir():
|
|
94
|
+
if file_path.is_file() and search_string in file_path.name:
|
|
95
|
+
matching_files.append(file_path)
|
|
96
|
+
|
|
97
|
+
return matching_files
|
|
98
|
+
|
|
99
|
+
def list_files(self, path, name):
|
|
100
|
+
files = self.list_files_containing(path, name)
|
|
101
|
+
for file in files:
|
|
102
|
+
print(file)
|
|
103
|
+
print(file.name)
|
|
104
|
+
|
|
105
|
+
def list_htmlparser_files(self, name):
|
|
106
|
+
files = self.list_files_containing(self.htmlparser_path, name)
|
|
107
|
+
for file in files:
|
|
108
|
+
print(file)
|
|
109
|
+
print(file.name)
|
|
110
|
+
print(file.stem)
|
|
111
|
+
print(file.suffix)
|
|
112
|
+
print(file.parent)
|
|
113
|
+
|
|
114
|
+
def list_bat1_files(self, name):
|
|
115
|
+
files = self.list_files_containing(self.bat1_path, name)
|
|
116
|
+
for file in files:
|
|
117
|
+
print(file)
|
|
118
|
+
print(file.name)
|
|
119
|
+
|
|
120
|
+
# utility_parts = ["clear", "count", "listtext"]
|
|
121
|
+
def list_utility_files(name, suffix):
|
|
122
|
+
list = Util.list_files(name, self.parts, suffix)
|
|
123
|
+
return list
|
|
124
|
+
|
|
125
|
+
def list_no_exist_file(preparex, part_list):
|
|
126
|
+
files =preparex.list_files_containing(path, list)
|
|
127
|
+
for file in files:
|
|
128
|
+
if file is not None:
|
|
129
|
+
print(f'{file.name} is found')
|
|
130
|
+
else:
|
|
131
|
+
print(f'{file.name} is not found')
|
|
132
|
+
|
|
133
|
+
if __name__ == "__main__":
|
|
134
|
+
preparex = Preparex()
|
|
135
|
+
name_left = "htmlparser_"
|
|
136
|
+
name_right = "Amazon-KU"
|
|
137
|
+
name = f'{name_left}{name_right}'
|
|
138
|
+
suffix = ".bat"
|
|
139
|
+
list = list_utility_files(name, suffix)
|
|
140
|
+
for fx in list:
|
|
141
|
+
print(f'fx={fx}')
|
|
142
|
+
|
|
143
|
+
bat1_files =preparex.list_files_containing(preparex.bat1_path, name)
|
|
144
|
+
for file in bat1_files:
|
|
145
|
+
print(f'1 file={file}')
|
|
146
|
+
if file is not None:
|
|
147
|
+
# print(f'2 {file.name} is found')
|
|
148
|
+
file_path = Path(file)
|
|
149
|
+
if str(file_path.name ) in list:
|
|
150
|
+
print( f'file_path.name={file_path.name} found' )
|
|
151
|
+
else:
|
|
152
|
+
print( f'file_path.name={file_path.name} not found' )
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Progress:
|
|
5
|
+
def __init__(self, meter_str: str, valuemin: str, valuemax: str, valuenow: str):
|
|
6
|
+
"""Represent an aria-style progress meter for Udemy cards.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
meter_str (str): Human readable label (e.g., ``"12%完了"``).
|
|
10
|
+
valuemin (str): Minimum value provided by the DOM attribute.
|
|
11
|
+
valuemax (str): Maximum value provided by the DOM attribute.
|
|
12
|
+
valuenow (str): Current progress value.
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
None
|
|
16
|
+
"""
|
|
17
|
+
self.meter_str = meter_str
|
|
18
|
+
self.valuemin = valuemin
|
|
19
|
+
self.valuemax = valuemax
|
|
20
|
+
self.valuenow = valuenow
|
|
21
|
+
self.meter = f"{self.valuemin}-{self.valuemax}-{self.valuenow}"
|
|
22
|
+
|
|
23
|
+
def to_dict(self) -> Dict[str, str]:
|
|
24
|
+
"""Expose the progress state as a serializable dict.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Dict[str, str]: Keys ``meter_str``, ``valuemin``, ``valuemax``,
|
|
28
|
+
``valuenow``, and ``meter``.
|
|
29
|
+
"""
|
|
30
|
+
return {
|
|
31
|
+
"meter_str": self.meter_str,
|
|
32
|
+
"valuemin": self.valuemin,
|
|
33
|
+
"valuemax": self.valuemax,
|
|
34
|
+
"valuenow": self.valuenow,
|
|
35
|
+
"meter": self.meter,
|
|
36
|
+
}
|
|
File without changes
|