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

This commit is contained in:
周中平 2023-11-06 14:46:18 +08:00
parent 69f883f0a5
commit ba7f8c0456
Signed by: zhouzhongping
GPG Key ID: 6666822800008000
5 changed files with 59 additions and 52 deletions

View File

@ -3,4 +3,3 @@ web = true
[blog]
rss =
data =

35
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,9 +34,34 @@ 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}")
# 渲染模板
# 服务模式
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(),

View File

@ -1,8 +1,9 @@
beautifulsoup4==4.12.2
blinker==1.6.3
blinker==1.7.0
certifi==2023.7.22
charset-normalizer==3.3.1
charset-normalizer==3.3.2
click==8.1.7
docopt==0.6.2
feedparser==6.0.10
Flask==3.0.0
idna==3.4

View File

@ -5,6 +5,7 @@ from urllib.parse import urlparse
from loguru import logger
import const
from src.tools import check_website_status
@ -69,30 +70,6 @@ class Config:
return '.'.join(domain_parts[-2:])
@property
def blog_data(self):
try:
data = self.config.get('blog', 'data', fallback=None)
except configparser.NoSectionError:
logger.error('未找到 section 配置项,请检查拼写')
return None
if not data:
logger.error('data 配置值为空')
return None
return json.loads(data)
@blog_data.setter
def blog_data(self, value):
if not self.config.has_section('blog'):
self.config.add_section('blog')
self.config.set('blog', 'data', json.dumps(value))
with open(self.path, 'w') as configfile:
self.config.write(configfile)
@property
def web_status(self):
try:
@ -103,10 +80,10 @@ class Config:
if web_status is None:
logger.error('web 配置值为空')
return True
return const.SITE_SERVICE_WEB
if web_status == "True" or web_status == "true":
return True
if web_status == "True" or web_status == "true" or web_status == "t" or web_status == "T":
return const.SITE_SERVICE_WEB
if web_status == "False" or web_status == "false":
return False
if web_status == "False" or web_status == "false" or web_status == "f" or web_status == "F":
return const.SITE_SERVICE_STATIC

View File

@ -1,15 +1,16 @@
# 站点标题
SITE_NAME = "EndOfYear"
# 站点服务模式
SITE_SERVICE_WEB = 1
SITE_SERVICE_STATIC = 0
# 时区
TIME_ZONE = "Asia/Shanghai"
# 时间格式
FORMAT_TIME = "%Y-%m-%d %H:%M:%S"
# 站点服务模式
SITE_SERVICE = 1
# 站点标题
SITE_NAME = "EndOfYear"
# 博客文章分类-生活
BLOG_POST_CATEGORY_LIFE = 1