27 lines
674 B
Python
27 lines
674 B
Python
import importlib
|
|
import os
|
|
|
|
import uvicorn
|
|
from settings import HOST, PORT
|
|
from defs import app, sqlite, loop
|
|
|
|
# 遍历 apis 文件夹下的所有文件,并且使用 importlib 导入
|
|
# 从而实现自动导入
|
|
for root, dirs, files in os.walk("apis"):
|
|
start_index = root.replace(os.sep, ".")
|
|
for filename in files:
|
|
if filename.endswith(".py"):
|
|
importlib.import_module(f"{start_index}.{filename[:-3]}")
|
|
|
|
|
|
async def main():
|
|
await sqlite.create_db_and_tables()
|
|
server = uvicorn.Server(
|
|
config=uvicorn.Config(app, host=HOST, port=PORT)
|
|
)
|
|
await server.serve()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
loop.run_until_complete(main())
|