This repository was archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate.py
More file actions
76 lines (68 loc) · 2.12 KB
/
Copy pathgenerate.py
File metadata and controls
76 lines (68 loc) · 2.12 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
from typing import Union
import dominate
from dominate.tags import *
import pdfkit
from get_data import *
def to_html(aws: list, save_path: Union[None, str] = None):
chooses = []
roles = []
pictures = []
reads = []
for answer in aws:
match answer:
case Choose():
chooses.append(answer)
case Role():
roles.append(answer)
case Picture():
pictures.append(answer)
case Read():
reads.append(answer)
doc = dominate.document(title="result")
with doc.head:
meta(charset="utf-8")
with doc.body:
h1("听后选择")
for choose in chooses:
h2("原文:")
for textual in choose.textual:
p(textual)
for c in choose.questions:
h3(c['stem'])
for option in c['options']:
p(option)
h4(f"Answer: {c['answer']}")
br()
br()
h1("听后回答")
for role in roles:
h2("原文")
for textual in role.textual:
p(textual)
for ro in role.questions:
h3(ro['stem'])
for answer in ro['answer']:
p(answer)
br()
br()
h1("听后转述")
for picture in pictures:
for answer in picture.answers:
p(answer)
br()
br()
h1("朗读短文")
for read in reads:
p(read.textual)
if save_path is None:
return doc.render()
elif isinstance(save_path, str):
with open(save_path, "w", encoding="utf-8") as f:
f.write(doc.render())
def to_pdf(aws: list, save_path="result.pdf"):
doc = to_html(aws)
# 将wkhtmltopdf.exe程序绝对路径传入config对象
path_wkthmltopdf = r'include\\wkhtmltox\\bin\\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)
# 生成pdf文件,to_file为文件路径
pdfkit.from_string(doc, save_path, configuration=config, verbose=True)