From 4f5f83d3faaac6de552aadd5a3f188e8883b9fc4 Mon Sep 17 00:00:00 2001 From: ccgo <> Date: Thu, 22 Feb 2024 00:07:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0sqlite=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/db_config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/db_config.py b/config/db_config.py index d3f1d14..f7d9748 100644 --- a/config/db_config.py +++ b/config/db_config.py @@ -7,3 +7,6 @@ REDIS_DB_PWD = os.getenv("REDIS_DB_PWD", "123456") # your redis password # mysql config RELATION_DB_PWD = os.getenv("RELATION_DB_PWD", "123456") # your relation db password RELATION_DB_URL = f"mysql://root:{RELATION_DB_PWD}@localhost:3306/media_crawler" + +# sqlite3 config +# RELATION_DB_URL = f"sqlite://data/media_crawler.sqlite" \ No newline at end of file From c09f9fef6899843b99ad5c4cd519e606525a77a6 Mon Sep 17 00:00:00 2001 From: ccgo <> Date: Thu, 22 Feb 2024 00:11:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0db.close()?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E5=86=B3=E6=8A=93=E5=8F=96=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=AE=8C=E4=B8=8D=E9=80=80=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.py | 2 ++ main.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/db.py b/db.py index 8ec4d5d..b1bc15e 100644 --- a/db.py +++ b/db.py @@ -18,6 +18,8 @@ async def init_db(create_db: bool = False) -> None: _create_db=create_db ) +async def close() -> None: + await Tortoise.close_connections() async def init(): await init_db(create_db=True) diff --git a/main.py b/main.py index 7c6a82b..73a1cfc 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,9 @@ async def main(): crawler_type=args.type ) await crawler.start() + + if config.SAVE_DATA_OPTION == "db": + await db.close() if __name__ == '__main__':