forked from lewis-007/MediaCrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.py
31 lines (21 loc) · 734 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from typing import List
from tortoise import Tortoise, run_async
from config.db_config import *
from tools import utils
def get_platform_models() -> List[str]:
models = ["store.xhs", "store.douyin", "store.bilibili", "store.kuaishou", "store.weibo"]
return models
async def init_db(create_db: bool = False) -> None:
await Tortoise.init(
db_url=RELATION_DB_URL,
modules={'models': get_platform_models()},
_create_db=create_db
)
async def close() -> None:
await Tortoise.close_connections()
async def init():
await init_db(create_db=True)
await Tortoise.generate_schemas()
utils.logger.info("[db.init] Init DB Success!")
if __name__ == '__main__':
run_async(init())