-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch_16.py
More file actions
365 lines (310 loc) · 10.3 KB
/
Copy pathscratch_16.py
File metadata and controls
365 lines (310 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import csv
import time
import requests
from bs4 import BeautifulSoup, PageElement
import os
# 假设CSV文件名为cards.csv,并且它包含data-id列
csv_file = r'.\cards.csv'
output_dir_img = r'./assets\output_card_img' # 设置输出图像目录
output_dir_desc = r'./assets\output_card_desc' # 设置输出描述目录
# 确保输出目录存在
if not os.path.exists(output_dir_img):
os.makedirs(output_dir_img)
if not os.path.exists(output_dir_desc):
os.makedirs(output_dir_desc)
# 读取CSV文件并提取data-id
data_ids = []
with open(csv_file, newline='', encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data_ids.append(row['data-id'])
c = 0
patchname = "Core"
# 遍历data-id列表
for data_id in data_ids:
c += 1
url = f'https://gwent.one/cn/export/image/card/{data_id}'
response = requests.get(url)
# 检查请求是否成功
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
# 找到卡片图像部分
gwent_card_img_div = soup.find('div', class_='h2c-img-wrap')
if gwent_card_img_div:
# 获取类名列表
class_list = gwent_card_img_div.find('div', class_='card-art').get('class')
# 将类名列表转换为字符串
class_str = ' '.join(class_list)
# 替换类名中的 'art_size-low' 为 'art_size-max'
class_str = class_str.replace('art_size-low', 'art_size-max')
# 将修改后的字符串转换回类名列表
updated_class_list = class_str.split()
# 更新元素的类名
gwent_card_img_div.find('div', class_='card-art')['class'] = updated_class_list
# 创建图像HTML文件
card_img_html = """<html><head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="./eimg.css">
<link rel="stylesheet" type="text/css" href="./cardart-v9.css">
<link rel="stylesheet" type="text/css" href="./asset-v9.css">
<link rel="stylesheet" type="text/css" href="./rebuild_sy.css">
<style>
body {
display: flex;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f8f9fa;
}
.card {
width: 992px;
height: 1424px;
border: 1px solid #ccc;
border-radius: 20px;
background-color: #a18c6c;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
padding: 60px;
box-sizing: border-box;
background-image: url("cardpreview_paper_bg.png");
}
.h2c-txt-wrap {
font-size: 36px;
margin: 0;
text-align: left;
}
.h2c-card--header {
margin-bottom: 20px;
padding: 10px;
border-radius: 10px;
}
.h2c-card__title {
font-size: 48px;
font-weight: bold;
}
.h2c-card__category {
font-size: 24px;
/*color: #555;*/
}
.h2c-card--body {
font-size: 20px;
line-height: 1.5;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
background-color: rgba(255, 255, 255, 0.2);
}
.h2c-card__ability {
margin-bottom: 20px;
text-shadow: 2px 2px 4px #ffffff ;
}
.h2c-keyword {
display: none;
}
.h2c-flavor {
display: incline;
font-style: italic
padding: 10px;
border-radius: 10px;
}
.h2c-version {
display: none;
}
.card {
font-size: clamp(10px, 1vw, 48px);
}
.h2c-card--header, .h2c-card--body, .h2c-card__ability, .h2c-card__footer {
font-size: inherit;
}
.h2c-card__title {
font-size: clamp(16px, 8vw, 128px);
}
.h2c-card__category {
font-size: clamp(12px, 6vw, 48px);
}
.h2c-card--body {
font-size: clamp(10px, 4vw, 40px);
line-height: 1.5;
}
.h2c-card__ability {
font-size: 36px;
margin: 0;
text-align: left;
line-height: 1.5;
letter-spacing: 1px;
margin-bottom: 20px;
}
.h2c-card__header {
font-size: 36px;
margin: 0;
text-align: left;
line-height: 1.5;
letter-spacing: 1px;
margin-bottom: 20px;
}
.h2c-card--body {
margin-bottom: 15px;
}
.h2c-card__keyword {
line-height: 1.5;
letter-spacing: 0.5px;
}
.h2c-card__flavor {
margin-top: 20px;
font-size: 26px;
color: #555;
font-style: italic;
}
</style>
<title>Card Display</title>
</head>""" + f"<body>{str(gwent_card_img_div)}</body></html>".replace("art_size-low", "art_size-max")
card_img_file_path = os.path.join(output_dir_img, f"card_image_{data_id}.html")
with open(card_img_file_path, 'w', encoding='utf-8') as card_img_file:
card_img_file.write(card_img_html)
# 找到卡片描述部分(这里需要根据实际HTML结构调整选择器)
# 找到整个 h2c-wrap 元素
h2c_wrap = soup.find('div', class_='h2c-wrap')
# 移除 h2c-img-wrap 元素
if h2c_wrap:
h2c_wrap.find('div', class_='h2c-img-wrap').extract()
h2c_txt_wrap = h2c_wrap.find('div', class_="h2c-txt-wrap")
# 创建新的 footer div 元素
# new_footer_div = soup.new_tag("div")
# new_footer_div.attrs[("class")] = "left-footer" # 使用三元组设置属性
# new_footer_div.string = f"Pack {patchname} {c}/{len(data_ids)} © 2024 CD PROJEKT S.A. Physical Card Creator X.Mimi"
# 将新的 footer div 插入到 h2c-wrap 元素的末尾
# h2c_txt_wrap.append(new_footer_div)
card_desc_html = """<html><head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="./eimg.css">
<link rel="stylesheet" type="text/css" href="./cardart-v9.css">
<link rel="stylesheet" type="text/css" href="./asset-v9.css">
<link rel="stylesheet" type="text/css" href="./rebuild_sy.css">
<style>
body {
display: flex;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #f8f9fa;
}
.h2c-txt-wrap {
width: 992px;
height: 1424px;
border: 1px solid #ccc;
border-radius: 20px;
background-color: #a18c6c;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
padding: 60px;
box-sizing: border-box;
background-image: url("cardpreview_paper_bg.png");
}
.h2c-txt-wrap {
font-size: 36px;
margin: 0;
text-align: left;
}
.h2c-card--header {
margin-bottom: 20px;
padding: 10px;
border-radius: 10px;
}
.h2c-card__title {
font-size: 48px;
font-weight: bold;
}
.h2c-card__category {
font-size: 24px;
/*color: #555;*/
}
.h2c-card--body {
font-size: 20px;
line-height: 1.5;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
background-color: rgba(255, 255, 255, 0.2);
}
.h2c-card__ability {
margin-bottom: 20px;
text-shadow: 2px 2px 4px #ffffff ;
}
.h2c-keyword {
display: none;
}
.h2c-flavor {
display: incline;
font-style: italic
padding: 10px;
border-radius: 10px;
}
.h2c-version {
display: none;
}
.card {
font-size: clamp(10px, 1vw, 48px);
}
.h2c-card--header, .h2c-card--body, .h2c-card__ability, .h2c-card__footer {
font-size: inherit;
}
.h2c-card__title {
font-size: clamp(16px, 8vw, 128px);
}
.h2c-card__category {
font-size: clamp(12px, 6vw, 48px);
}
.h2c-card--body {
font-size: clamp(10px, 4vw, 40px);
line-height: 1.5;
}
.h2c-card__ability {
font-size: 36px;
margin: 0;
text-align: left;
line-height: 1.5;
letter-spacing: 1px;
margin-bottom: 20px;
}
.h2c-card__header {
font-size: 36px;
margin: 0;
text-align: left;
line-height: 1.5;
letter-spacing: 1px;
margin-bottom: 20px;
}
.h2c-card--body {
margin-bottom: 15px;
}
.h2c-card__keyword {
line-height: 1.5;
letter-spacing: 0.5px;
}
.h2c-card__flavor {
margin-top: 20px;
font-size: 26px;
color: #555;
font-style: italic;
}
.left-footer {
position: absolute; /* 绝对定位 */
left: 30px; /* 距离左边界10px,确保不超出左边界 */
bottom: 30px; /* 距离底部10px */
font-size: 18px; /* 小号字体 */
color: black; /* 黑色文字 */
text-align: left; /* 文字左对齐 */
padding: 5px; /* 内边距 */
z-index: 10; /* 确保在卡牌内容上方 */
}
</style>
<title>Card Display</title>
</head>""" + f"<body>{str(h2c_wrap)}"+"</body></html>"
card_desc_file_path = os.path.join(output_dir_desc, f"card_description_{data_id}.html")
with open(card_desc_file_path, 'w', encoding='utf-8') as card_desc_file:
card_desc_file.write(card_desc_html)
time.sleep(1)
print(f"Processed {c} cards.")
print("All card images and descriptions have been saved as separate HTML files.")