From b5bee828cafa8858d8ab13e1fb41c18dd40ffddd Mon Sep 17 00:00:00 2001 From: zhouzhongping Date: Mon, 6 Nov 2023 16:24:08 +0800 Subject: [PATCH] =?UTF-8?q?BUG:=20=E4=BF=AE=E5=A4=8D=E5=BA=93=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 包内使用相对导入 - 包外使用绝对导入 --- main.py | 11 +++++------ src/__init__.py | 0 src/analyzer.py | 2 +- src/config.py | 5 ++--- src/generator.py | 4 ++-- src/scraper.py | 6 +++--- src/tools.py | 2 +- templates/painting.html | 2 +- 8 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 src/__init__.py diff --git a/main.py b/main.py index 1e8d45f..40dc75a 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ from flask import Flask, render_template, redirect, url_for from loguru import logger -import const -import models -import tools -from config import Config -from generator import Generator +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") @@ -41,7 +41,6 @@ def painting(): 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: diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/analyzer.py b/src/analyzer.py index 8c501e6..640cd32 100644 --- a/src/analyzer.py +++ b/src/analyzer.py @@ -5,7 +5,7 @@ from loguru import logger from lunardate import LunarDate from snownlp import SnowNLP -import const +from . import const # 计算文本内容情感分数 diff --git a/src/config.py b/src/config.py index e4e5b74..445a91b 100644 --- a/src/config.py +++ b/src/config.py @@ -1,12 +1,11 @@ import configparser -import json import os from urllib.parse import urlparse from loguru import logger -import const -from src.tools import check_website_status +from . import const +from .tools import check_website_status class Config: diff --git a/src/generator.py b/src/generator.py index 60e85ba..6a86ac4 100644 --- a/src/generator.py +++ b/src/generator.py @@ -2,8 +2,8 @@ from functools import lru_cache from loguru import logger -import models -import scraper +from . import models +from . import scraper @lru_cache(maxsize=None) diff --git a/src/scraper.py b/src/scraper.py index 5a186bc..63f260b 100644 --- a/src/scraper.py +++ b/src/scraper.py @@ -4,9 +4,9 @@ from collections import Counter import feedparser from loguru import logger -import analyzer -import const -import tools +from . import analyzer +from . import const +from . import tools class Blog: diff --git a/src/tools.py b/src/tools.py index 9271267..e2e7c8b 100644 --- a/src/tools.py +++ b/src/tools.py @@ -7,7 +7,7 @@ from bs4 import BeautifulSoup from dateutil.parser import parse from loguru import logger -import const +from . import const def check_website_status(url): diff --git a/templates/painting.html b/templates/painting.html index 992902f..1fbede7 100644 --- a/templates/painting.html +++ b/templates/painting.html @@ -79,7 +79,7 @@
-

在{{ special_post.date }}那天,你写下了

+

在{{ special_post.date }}那天,写下了

{{ special_post.title }}

{{ special_post.content[:50] }}……