修改保存图片方法
This commit is contained in:
parent
f49208b0f7
commit
a5596ef287
@ -130,7 +130,7 @@ async def get_all_visitor_pictures(pageNo=1, pageSize=10, visitorStatus=1):
|
||||
visitor_ids_add.append(visitor["visitorId"])
|
||||
# 获取图片
|
||||
try:
|
||||
await HaikangUtil.query_visitor_record_pictures(visitor["svrIndexCode"], visitor["picUri"], f"./visitor/face_images/{visitor['visitorName']}.jpg")
|
||||
await HaikangUtil.query_visitor_record_pictures(visitor["svrIndexCode"], visitor["picUri"], f"./visitor/face_images/{visitor['visitorName']}")
|
||||
await asyncio.sleep(1)
|
||||
except Exception as e:
|
||||
print(e, visitor["visitorId"])
|
||||
@ -168,7 +168,7 @@ async def get_all_employee_pictures(pageNo=1, pageSize=500):
|
||||
person_ids_add.append(employee["personId"])
|
||||
# 获取图片
|
||||
try:
|
||||
await HaikangUtil.get_person_picture(employee.get("personPhoto")[0]["serverIndexCode"], employee.get("personPhoto")[0]["picUri"], f"./employee/face_images/{employee['personName']}.jpg")
|
||||
await HaikangUtil.get_person_picture(employee.get("personPhoto")[0]["serverIndexCode"], employee.get("personPhoto")[0]["picUri"], f"./employee/face_images/{employee['personName']}")
|
||||
await asyncio.sleep(0.5)
|
||||
except Exception as e:
|
||||
print(f"error: {e}, personId: {employee['personId']}")
|
||||
|
||||
@ -2,6 +2,8 @@ import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import base64
|
||||
import os
|
||||
|
||||
import requests
|
||||
import httpx
|
||||
from fastapi import HTTPException
|
||||
@ -464,7 +466,7 @@ class HaikangUtil:
|
||||
|
||||
# 获取访客记录中的图片
|
||||
@classmethod
|
||||
async def query_visitor_record_pictures(cls, svrIndexCode: str, picUri: str, save_path: str="persion.jpg"):
|
||||
async def query_visitor_record_pictures(cls, svrIndexCode: str, picUri: str, save_path):
|
||||
"""获取访客记录中的图片
|
||||
|
||||
Args:
|
||||
@ -488,6 +490,9 @@ class HaikangUtil:
|
||||
|
||||
back = await cls.send_request("POST", url, headers, body_json, False)
|
||||
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
save_path = os.path.join(save_path, picUri.split('/')[-1]+".jpg")
|
||||
|
||||
with open(save_path, 'wb') as f:
|
||||
for chunk in back.iter_bytes(chunk_size=8192):
|
||||
if chunk: # 忽略 keep-alive 的空 chunk
|
||||
@ -518,7 +523,7 @@ class HaikangUtil:
|
||||
|
||||
# 提取人员图片
|
||||
@classmethod
|
||||
async def get_person_picture(cls, serverIndexCode, picUri, save_path: str="persion.jpg"):
|
||||
async def get_person_picture(cls, serverIndexCode, picUri, save_path):
|
||||
|
||||
url = f"{HaiKangConfig.HAIKANG_URL}:{HaiKangConfig.HAIKANG_PORT}/artemis{HaiKangConfig.HAIKANG_GET_PERSON_PICTURE}"
|
||||
body_dict = {
|
||||
@ -534,6 +539,9 @@ class HaikangUtil:
|
||||
|
||||
back = await cls.send_request("POST", url, headers, body_json, False)
|
||||
|
||||
os.makedirs(save_path, exist_ok=True)
|
||||
save_path = os.path.join(save_path, picUri.split('/')[-1]+".jpg")
|
||||
|
||||
with open(save_path, 'wb') as f:
|
||||
for chunk in back.iter_bytes(chunk_size=8192):
|
||||
if chunk: # 忽略 keep-alive 的空 chunk
|
||||
|
||||
Loading…
Reference in New Issue
Block a user