Skip to content

Commit 2cb2cea

Browse files
committed
完成PageRenderer类
1 parent 7b50496 commit 2cb2cea

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

Alpha/PageRenderer.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!python3
2+
# -*- coding: utf-8 -*-
3+
'''
4+
@Author: Sion10032
5+
@LastEditors: Sion10032
6+
@Description: 渲染邮件html页面
7+
@Date: 2019-02-25
8+
@LastEditTime: 2019-02-25
9+
'''
10+
11+
import Card
12+
import Dynamic
13+
14+
class PageRenderer:
15+
16+
def __init__(self):
17+
self.wrapper = open('./Templates/Wrapper.html', 'r', encoding='UTF-8').read()
18+
self.listItem = open('./Templates/ListItem.html', 'r', encoding='UTF-8').read()
19+
self.videoInfo = open('./Templates/VideoInfo.html', 'r', encoding='UTF-8').read()
20+
21+
def Render(self, cards):
22+
result = self.wrapper
23+
listItems = ''
24+
25+
cs = {}
26+
for card in cards:
27+
if not card.uname in cs:
28+
cs[card.uname] = []
29+
cs[card.uname].append(card)
30+
31+
for key, value in cs.items():
32+
li = self.listItem
33+
li = li.replace('{ UPName }', key)
34+
35+
vfs = ''
36+
for card in value:
37+
vfs = vfs + self.__RenderVideoInfo(card)
38+
li = li.replace('{ VideoInfo }', vfs)
39+
40+
listItems = listItems + li
41+
42+
result = result.replace('{ list-item }', listItems)
43+
44+
return result
45+
46+
def __RenderVideoInfo(self, card):
47+
vi = self.videoInfo
48+
49+
vi = vi.replace('{ VideoLink }', 'https://www.bilibili.com/video/av' + str(card.av))
50+
vi = vi.replace('{ CoverImgSrc }', card.cover + '@160w_100h.webp')
51+
vi = vi.replace('{ VideoTitle }', card.title)
52+
vi = vi.replace('{ VideoDescription }', card.desc.replace('\n', '<br />'))
53+
54+
return vi
55+
56+
if __name__ == '__main__':
57+
cs = Dynamic.ListUpdate()
58+
pr = PageRenderer()
59+
print(pr.Render(cs))

Alpha/Templates/ListItem.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<li class="up-list">
2+
<div class="card">
3+
<h3>{ UPName }</h3>
4+
{ VideoInfo }
5+
</div>
6+
</li>

Alpha/Templates/VideoInfo.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="video-info-wrapper">
2+
<a href="{ VideoLink }">
3+
<img class="video-cover-img" src="{ CoverImgSrc }">
4+
</a>
5+
<div class="video-info">
6+
<strong>{ VideoTitle }</strong>
7+
<p class="detail-info">
8+
{ VideoDescription }
9+
</p>
10+
</div>
11+
</div>

Alpha/Templates/Wrapper.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
</head>
6+
<body>
7+
<ul class="card-wrapper">
8+
{ list-item }
9+
</ul>
10+
</body>
11+
<style type="text/css">
12+
* {
13+
margin: 0;
14+
padding: 0;
15+
box-sizing: border-box;
16+
}
17+
body {
18+
padding: 5px;
19+
}
20+
.card-wrapper {
21+
width: 100%;
22+
padding-left: 20px;
23+
}
24+
.up-list {
25+
margin-bottom: 20px;
26+
}
27+
.card {
28+
width: 100%;
29+
}
30+
.video-info-wrapper {
31+
height: 100px;
32+
display: flex;
33+
margin-top: 10px;
34+
}
35+
.video-cover-img {
36+
flex-shrink: 0;
37+
width: 160px;
38+
height: 100px;
39+
object-fit: cover;
40+
}
41+
.video-info {
42+
flex-grow: 1;
43+
margin-left: 10px;
44+
display: flex;
45+
flex-direction: column;
46+
}
47+
.detail-info {
48+
margin-top: 5px;
49+
font-size: 12px;
50+
overflow: hidden;
51+
width: 100%;
52+
max-height: 64px;
53+
}
54+
</style>
55+
</html>

0 commit comments

Comments
 (0)