代码拉取完成,页面将自动刷新
from socketserver import BaseRequestHandler, ThreadingTCPServer
from app import app
from flask_sqlalchemy import SQLAlchemy
from models import GroupOfPeople, Camera
from exts import get_time
# app.app_context().push()
db = SQLAlchemy(app)
class Handler(BaseRequestHandler):
def handle(self) -> None:
address, pid = self.client_address
print(f'{address} connected!')
while True:
data = self.request.recv(1024)
if len(data) <= 0:
print("close!")
break
print(f'receive data: {data.decode()}')
data_dict = eval(data.decode())
# 存入数据库
camera = db.session.query(Camera).filter(Camera.ipv4 == data_dict.get("ip")).first()
if camera is None:
camera = Camera(ipv4=data_dict.get("ip"),
place="未知",
state="未加入系统中的摄像头")
gop = GroupOfPeople(time=get_time(),
mask=data_dict.get("mask"),
no_mask=data_dict.get("no_mask"),
camera=camera)
db.session.add(gop)
db.session.commit()
if __name__ == '__main__':
server = ThreadingTCPServer(('0.0.0.0', 5001), Handler)
print("Listening")
server.serve_forever()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。