Merge pull request #136 from jayeeliu/main

增加sqlite配置示例,解决用sqlite保存数据时,抓取结束不退出的问题
This commit is contained in:
relakkes 2024-02-22 21:32:19 +08:00 committed by GitHub
commit 67d2b7cff8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 0 deletions

View File

@ -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"

2
db.py
View File

@ -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)

View File

@ -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__':