-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepage.py
42 lines (37 loc) · 1.42 KB
/
makepage.py
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
from datetime import datetime
def make_page(contents, content_length=100):
print("start make page")
template_datatable = None
with open("template/datatable.html", "r", encoding="utf-8", errors="ignore") as f:
template_datatable = f.read()
randerText = None
with open("template/rander.html", "r", encoding="utf-8", errors="ignore") as f:
randerText = f.read()
data_list = []
for c in contents:
"""
<tr>
<td>{newsTitle}</td>
<td><a href="{newsLink}">{newsDetail}</a></td>
</tr>
"""
description = ""
if "detail" in c.keys():
print(c["detail"])
if isinstance(c["detail"], dict):
description = c["detail"]["description"]
if len(description) > content_length:
description = description[:content_length] + "..."
datatable = template_datatable.format(
newsTitle=c["title"],
newsDate=c["date"],
newsLink=c["link"],
newsDetail=description,
)
data_list.append(datatable)
print(data_list)
today = datetime.strftime(datetime.now(), "%Y-%m-%d")
randerText = randerText.format(Date=today, datatable="\n".join(data_list))
with open("pages/index.html", "w", encoding="utf-8") as w:
w.write(randerText)
print("make compelte...!")