功能:离线模式&更新依赖

This commit is contained in:
2023-11-06 14:46:18 +08:00
parent e2162321fd
commit 8b9c8bd0b1
5 changed files with 59 additions and 52 deletions

53
main.py
View File

@@ -4,6 +4,7 @@ from loguru import logger
import const
import models
import tools
from config import Config
from generator import Generator
app = Flask(__name__)
@@ -18,9 +19,12 @@ def home():
@app.route('/painting')
def painting():
# 读取配置文件
config = Config("config.ini")
# 站点数据
site = models.Site(
service=const.SITE_SERVICE,
service=config.web_status,
title=const.SITE_NAME
).to_dict()
@@ -30,18 +34,43 @@ def painting():
).to_dict()
# 初始化数据生成器
generator = Generator("https://blog.7wate.com/rss.xml")
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()}")
logger.info(f"Custom: {custom}")
# 渲染模板
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 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__':