style: 格式化代码
This commit is contained in:
13
main.py
13
main.py
@@ -23,13 +23,11 @@ from lxml import etree
|
|||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
models.Base.metadata.create_all(bind=engine)
|
models.Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Dependency
|
# Dependency
|
||||||
def get_db():
|
def get_db():
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
@@ -57,8 +55,7 @@ def create_user(user: schemas.User, db: Session = Depends(get_db)):
|
|||||||
print('db_user', db_user)
|
print('db_user', db_user)
|
||||||
|
|
||||||
if db_user:
|
if db_user:
|
||||||
raise HTTPException(status_code=400,
|
raise HTTPException(status_code=400, detail="wxid already registered")
|
||||||
detail="wxid already registered")
|
|
||||||
return crud.create_user(db=db, user=user)
|
return crud.create_user(db=db, user=user)
|
||||||
|
|
||||||
|
|
||||||
@@ -77,6 +74,7 @@ def read_user(user:schemas.User, db: Session = Depends(get_db)):
|
|||||||
raise HTTPException(status_code=404, detail="openId not found")
|
raise HTTPException(status_code=404, detail="openId not found")
|
||||||
return db_user
|
return db_user
|
||||||
|
|
||||||
|
|
||||||
# 根据wxid查询用户
|
# 根据wxid查询用户
|
||||||
@app.get("/users")
|
@app.get("/users")
|
||||||
def read_user(wxid, db: Session = Depends(get_db)):
|
def read_user(wxid, db: Session = Depends(get_db)):
|
||||||
@@ -85,6 +83,7 @@ def read_user(wxid, db: Session = Depends(get_db)):
|
|||||||
raise HTTPException(status_code=404, detail="User-wxid not found")
|
raise HTTPException(status_code=404, detail="User-wxid not found")
|
||||||
return db_user
|
return db_user
|
||||||
|
|
||||||
|
|
||||||
# 监听机器人http-get消息
|
# 监听机器人http-get消息
|
||||||
@app.get("/wxbot")
|
@app.get("/wxbot")
|
||||||
def helloget(q: dict):
|
def helloget(q: dict):
|
||||||
@@ -93,6 +92,7 @@ def helloget(q:dict):
|
|||||||
t.start()
|
t.start()
|
||||||
return json.dumps({"Code": 0})
|
return json.dumps({"Code": 0})
|
||||||
|
|
||||||
|
|
||||||
# 监听机器人post日志消息
|
# 监听机器人post日志消息
|
||||||
@app.post("/wxbot")
|
@app.post("/wxbot")
|
||||||
# def hellopost(requestData:schemas.User):
|
# def hellopost(requestData:schemas.User):
|
||||||
@@ -103,6 +103,7 @@ def hellopost(requestData:dict):
|
|||||||
t.start()
|
t.start()
|
||||||
return json.dumps({"Code": 0})
|
return json.dumps({"Code": 0})
|
||||||
|
|
||||||
|
|
||||||
# 保存好友信息
|
# 保存好友信息
|
||||||
def saveWxidInfo(account_wxid, wxid):
|
def saveWxidInfo(account_wxid, wxid):
|
||||||
allFriend = WXBotService.get_address_list(account_wxid)
|
allFriend = WXBotService.get_address_list(account_wxid)
|
||||||
@@ -113,7 +114,6 @@ def saveWxidInfo(account_wxid,wxid):
|
|||||||
create_user(db=SessionLocal(), user=friendItemObj)
|
create_user(db=SessionLocal(), user=friendItemObj)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 发送小程序模版,建议远程更新
|
# 发送小程序模版,建议远程更新
|
||||||
def sendminiProgram(data, account_wxid, wxid, msgXml):
|
def sendminiProgram(data, account_wxid, wxid, msgXml):
|
||||||
# 发送小程序
|
# 发送小程序
|
||||||
@@ -240,11 +240,9 @@ def kp(event_data):
|
|||||||
# print('userClass====',type(userClass))
|
# print('userClass====',type(userClass))
|
||||||
# crud.create_user(db=SessionLocal(),user=userClass)
|
# crud.create_user(db=SessionLocal(),user=userClass)
|
||||||
|
|
||||||
|
|
||||||
# 保存好友信息
|
# 保存好友信息
|
||||||
saveWxidInfo(account_wxid, wxid)
|
saveWxidInfo(account_wxid, wxid)
|
||||||
|
|
||||||
|
|
||||||
elif msg_type == 3: # 3 图片消息
|
elif msg_type == 3: # 3 图片消息
|
||||||
kp_log = f'{type_str} 图片消息 内容:{filepath}'
|
kp_log = f'{type_str} 图片消息 内容:{filepath}'
|
||||||
# 本地dat图片解密
|
# 本地dat图片解密
|
||||||
@@ -356,4 +354,3 @@ def kp(event_data):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print(kp_log)
|
print(kp_log)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user