def tongbuCamera(request): try: secret = '9a7808bec80d4211b5fd7097750e3450' ip = '192.168.5.252' hk = HaiKangSDK(ip, secret) data = hk.getAllCamera() for each in data['data']['list']: c = Camera.objects.filter(cameraUuid=each['cameraUuid']) n = Camera.objects.filter(name=each['cameraName']) if n: first = n[0] first.addr = aes.encrypt( 'http://192.168.5.252:6713/mag/hls/%s/1/live.m3u8' % (each['cameraUuid'])) first.cameraUuid = each['cameraUuid'] first.onLineStatus = each['onLineStatus'] first.save() elif c: first = c[0] first.code = each['cameraName'] first.name = each['cameraName'] first.onLineStatus = each['onLineStatus'] first.save() else: addr = aes.encrypt( 'http://192.168.5.252:6713/mag/hls/%s/1/live.m3u8' % (each['cameraUuid'])) Camera.objects.create(addr=addr, code=each['cameraName'], onLineStatus=each['onLineStatus'], cameraUuid=each['cameraUuid']) return returnSucc(None) except: traceback.print_exc() return returnError(None)
def warn(request): if request.method == 'GET': c = RequestContext(request, locals()) if checkMobile(request): t = get_template('SMT/smt_warn.html') else: t = get_template('SMT/smt_warn.html') return HttpResponse(t.render(c)) elif request.method == 'POST': if request.META["HTTP_HOST"] == 'nginx-host': try: AlertZoneName = request.POST.get('AlertZoneName') if AlertZoneName: alarm = Alarm.objects.get_or_create(name=AlertZoneName)[0] name = alarmEvent[request.POST.get('EventCode')] station = Station.objects.get_or_create(name=name)[0] level = request.POST.get('Level') warn = Warning.objects.create(alarm=alarm, station=station, level=level) if level in [1, 2, 3]: before = None if alarm.station: before = alarm.station.IsAlarming #如果已经是报警状态避免重复报警直接返回 alarm.station = station alarm.save() if not before and station.IsAlarming: # floor = alarm.room.floor # zones = alarm.room.Zone.all() addr = '' if alarm.room: addr = alarm.room.fullname() p = { "first": "您好", "key1": alarm.station.name, "key2": addr + alarm.name, "key3": str(datetime.datetime.now()).split('.')[0], "remark": "如有问题,请联系{}".format(DEPNAME) } wxm = WeixinMessage.objects.get(title='安防报警提醒') e2us = wxm.e2u.all() for e2u in e2us: for user in e2u.users.all(): p['to_user'] = user wxm.sendwxmessage(1, **p) # for each in WeixinMessage.objects.filter(e2u__warnlevel=station).filter(Q(e2u__floors=floor)|Q(zones=zones)): # each.sendwxmessage(**p) # ele_by_floor =Element2User.objects.filter(floors = alarm.room.floor) # ele_by_zone =Element2User.objects.filter(zones = alarm.room.Zone.all()) # 发送微信模板消息 except: traceback.print_exc() return returnSucc(None)
def test(self, request): # body = json.loads(request.body) # log_id = body.get('log_id',None) # if PersonWarn.objects.filter(log_id=log_id).count()==0: # cameraUuid = body.get('cameraUuid',None) # c = Camera.objects.get(cameraUuid=cameraUuid) # PersonWarn.objects.create(camera=c,log_id=log_id) # PersonWarn.objects.last().weixin() return returnSucc(None)
def renliu(request): if request == 'fgf' or request.META["HTTP_HOST"] == 'nginx-host': try: secret = '9a7808bec80d4211b5fd7097750e3450' ip = '192.168.5.252' hk = HaiKangSDK(ip, secret) data = hk.getPeople() return returnSucc(None) except: traceback.print_exc() return returnError(None)
def warn(self, request): try: body = json.loads(request.body) log_id = body.get('log_id', None) if PersonWarn.objects.filter(log_id=log_id).count() == 0: extInfo = eval(body.get('extInfo', None)) timestr = extInfo[0]['snap']['absTimeStr'] faces = extInfo[0]['faces'] for face in faces: name = face['humanAttr']['name'] birthDate = face['humanAttr']['birthDate'] if birthDate: birthDate = datetime.datetime.strptime( birthDate, '%Y-%m-%d') try: p = Person.objects.get( personName=name, birthday__range=(birthDate, birthDate + relativedelta(days=1))) except: p = Person.objects.filter(personName=name).last() if not p: return returnSucc(None) cameraUuid = body.get('cameraUuid', None) cameraName = body.get('cameraName', None) try: c = Camera.objects.get(name=cameraName) except: c = Camera.objects.create(name=cameraName, code=cameraName, cameraUuid=cameraUuid) p = PersonWarn.objects.create(time=timestr, person=p, camera=c, log_id=log_id, degbug=str(body)) p.weixin() return returnSucc(None) except: traceback.print_exc()
def checkonline(request): if request == 'fgf' or request.META["HTTP_HOST"] == 'nginx-host': try: secret = '9a7808bec80d4211b5fd7097750e3450' ip = '192.168.5.252' hk = HaiKangSDK(ip, secret) hk.getPersonGroup() data = hk.getAllCamera() Camera.objects.update(onLineStatus=0) for each in data['data']['list']: c = Camera.objects.filter(cameraUuid=each['cameraUuid']) n = Camera.objects.filter(code=each['cameraName']) if n: first = n[0] first.addr = aes.encrypt( 'http://192.168.5.252:6713/mag/hls/%s/1/live.m3u8' % (each['cameraUuid'])) first.cameraUuid = each['cameraUuid'] first.onLineStatus = each['onLineStatus'] first.save() elif c: first = c[0] first.code = each['cameraName'] first.name = each['cameraName'] first.onLineStatus = each['onLineStatus'] first.save() else: addr = aes.encrypt( 'http://192.168.5.252:6713/mag/hls/%s/1/live.m3u8' % (each['cameraUuid'])) Camera.objects.create(addr=addr, code=each['cameraName'], name=each['cameraName'], onLineStatus=each['onLineStatus'], cameraUuid=each['cameraUuid']) return returnSucc(None) except: traceback.print_exc() return returnError(None)