2023-10-30 15:56:29 +08:00
|
|
|
from flask import Flask, render_template, redirect, url_for
|
|
|
|
from loguru import logger
|
|
|
|
|
2023-11-06 16:24:08 +08:00
|
|
|
from src import const
|
|
|
|
from src import models
|
|
|
|
from src import tools
|
|
|
|
from src.config import Config
|
|
|
|
from src.generator import Generator
|
2023-10-30 15:56:29 +08:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
logger.add("endofyear.log")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def home():
|
2023-11-03 16:58:54 +08:00
|
|
|
# 重定向 painting
|
2023-10-30 15:56:29 +08:00
|
|
|
return redirect(url_for('painting'))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/painting')
|
|
|
|
def painting():
|
2023-11-06 14:46:18 +08:00
|
|
|
# 读取配置文件
|
|
|
|
config = Config("config.ini")
|
|
|
|
|
2023-11-03 16:58:54 +08:00
|
|
|
# 站点数据
|
|
|
|
site = models.Site(
|
2023-11-06 14:46:18 +08:00
|
|
|
service=config.web_status,
|
2023-11-03 16:58:54 +08:00
|
|
|
title=const.SITE_NAME
|
|
|
|
).to_dict()
|
|
|
|
|
|
|
|
# 自定义数据
|
|
|
|
custom = models.Custom(
|
|
|
|
yiyan=tools.get_yiyan()
|
|
|
|
).to_dict()
|
|
|
|
|
|
|
|
# 初始化数据生成器
|
2023-11-06 14:46:18 +08:00
|
|
|
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
|
|
|
|
)
|
2023-10-30 15:56:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(host='0.0.0.0', port=7777, debug=True)
|