From bae9f4070f321b62f93b93585d38e4f8083d3ba6 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 17 Jun 2021 17:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=B3=E9=94=AE=E5=AD=97?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/service/local.py | 5 +++++ main.py | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/service/local.py b/lib/service/local.py index 00b01ea..4a5a302 100644 --- a/lib/service/local.py +++ b/lib/service/local.py @@ -8,3 +8,8 @@ def check_local(txt): if len(result) > 0: risk = 1 return {'errcode': 0, 'risk': risk, 'reason': result} + + +def replace_local(txt: str): + t = TextFilter() + return t.filter(txt) diff --git a/main.py b/main.py index 564e423..859ddd7 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,11 @@ # encoding:utf-8 -from fastapi import FastAPI +from fastapi import FastAPI, BackgroundTasks from pydantic import BaseModel import uvicorn from lib.service.baidu import check_baidu -from lib.service.local import check_local +from lib.service.local import check_local, replace_local from lib.service.wechat import msg_sec_check app = FastAPI() @@ -15,6 +15,10 @@ class Item(BaseModel): content: str +def begin_audit_task(task_id: str): + print('begin audit task: %s' % (task_id)) + + @app.post("/check_wx") async def check_with_wx(item: Item): res_wechat = await msg_sec_check(item.content) @@ -33,6 +37,19 @@ async def check_with_local(item: Item): return res_local +@app.post("/replace_local") +async def replace_with_local(item: Item): + res_local = replace_local(item.content) + return res_local + + +# @app.post("/begin_task") +# async def begin_task(item: Item, background_tasks: BackgroundTasks): +# res_local = check_local(item.content) +# background_tasks.add_task(begin_audit_task, item.content) +# return res_local + + @app.post("/check_all") async def check_content(item: Item): res_wechat = await msg_sec_check(item.content)