-
Notifications
You must be signed in to change notification settings - Fork 212
/
main.py
37 lines (32 loc) · 1.05 KB
/
main.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
32
33
34
35
36
37
from fastapi import FastAPI
from importlib import import_module
from lib.logger import logger
import uvicorn
import yaml
import argparse
import os
CONFIG_PATH = ''
app = FastAPI()
services = ['xhs', 'weibo', 'taobao', 'kuaishou', 'jd', 'douyin', 'bilibili', 'proxies']
def register_router():
for service in services:
module = import_module(f'service.{service}.urls')
app.include_router(getattr(module, 'router'))
def init_service():
global CONFIG_PATH
if CONFIG_PATH == '':
CONFIG_PATH = os.getenv("FILE", 'config/config.yaml')
with open(CONFIG_PATH, 'r') as f:
config = yaml.safe_load(f)
logger.setup(config)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Crawler server.')
parser.add_argument('-f', '--file', type=str, help='path of config file', default='config/config.yaml')
args = parser.parse_args()
CONFIG_PATH = args.file
register_router()
init_service()
uvicorn.run("main:app", host="0.0.0.0", port=8080)
else:
register_router()
init_service()