Skip to content

Commit

Permalink
Merge pull request #136 from jayeeliu/main
Browse files Browse the repository at this point in the history
增加sqlite配置示例,解决用sqlite保存数据时,抓取结束不退出的问题
  • Loading branch information
NanmiCoder authored Feb 22, 2024
2 parents 03ca445 + c09f9fe commit 67d2b7c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/db_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
# 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 changes: 2 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit 67d2b7c

Please sign in to comment.