forked from SevenWate/EndOfYear
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
76 lines (62 loc) · 2.45 KB
/
main.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
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 flask import Flask, render_template, redirect, url_for
from loguru import logger
from src import const
from src import models
from src import tools
from src.config import Config
from src.generator import Generator
app = Flask(__name__)
logger.add("endofyear.log")
@app.route('/')
def home():
# 重定向 painting
return redirect(url_for('painting'))
@app.route('/painting')
def painting():
# 读取配置文件
config = Config("config.ini")
# 站点数据
site = models.Site(
service=config.web_status,
title=const.SITE_NAME
).to_dict()
# 自定义数据
custom = models.Custom(
yiyan=tools.get_yiyan()
).to_dict()
# 初始化数据生成器
generator = Generator(config.rss_url)
logger.info(f"Site: {site}")
logger.info(f"Blog: {generator.blog()}")
logger.info(f"Special Post: {generator.special_post()}")
logger.info(f"Sentiment Post: {generator.sentiment_post()}")
logger.info(f"Long Post: {generator.long_post()}")
logger.info(f"Short Post: {generator.short_post()}")
# 服务模式
if config.web_status == const.SITE_SERVICE_STATIC:
# 静态网站模式
html_static_file = render_template('painting.html',
site=site,
blog=generator.blog(),
special_post=generator.special_post(),
sentiment_post=generator.sentiment_post(),
long_post=generator.long_post(),
short_post=generator.short_post(),
custom=custom
)
with open("static/index.html", "w") as f:
f.write(html_static_file)
return 'OK'
else:
# web 模式
return render_template('painting.html',
site=site,
blog=generator.blog(),
special_post=generator.special_post(),
sentiment_post=generator.sentiment_post(),
long_post=generator.long_post(),
short_post=generator.short_post(),
custom=custom
)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7777, debug=True)