|
@@ -3,12 +3,15 @@
|
|
|
# @Time : 2025/7/22 17:20
|
|
|
import threading
|
|
|
import time
|
|
|
+from typing import Dict, Union
|
|
|
|
|
|
+import requests
|
|
|
from django.views import View
|
|
|
|
|
|
from Model.models import AlexaPush
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
-from AnsjerPush.config import CONFIG_INFO, CONFIG_EUR
|
|
|
+from AnsjerPush.config import CONFIG_INFO, CONFIG_EUR, ALEXA_DOMAIN, ERROR_INFO_LOGGER
|
|
|
from Service.DevicePushService import DevicePushService
|
|
|
|
|
|
|
|
@@ -51,10 +54,11 @@ class AlexaView(View):
|
|
|
'event_time': event_time,
|
|
|
'storage_location': storage_location,
|
|
|
}
|
|
|
- # 异步推送消息和保存数据
|
|
|
- threading.Thread(
|
|
|
+ # 保存数据和发送Alexa事件
|
|
|
+ thread = threading.Thread(
|
|
|
target=cls.save_data_and_send_alexa_event,
|
|
|
- kwargs=kwargs).start()
|
|
|
+ kwargs=kwargs)
|
|
|
+ thread.start()
|
|
|
|
|
|
kwargs.pop('event_type')
|
|
|
res_data: str = DevicePushService.get_oci_req_url(**kwargs)
|
|
@@ -63,6 +67,31 @@ class AlexaView(View):
|
|
|
|
|
|
@staticmethod
|
|
|
def save_data_and_send_alexa_event(**kwargs):
|
|
|
- kwargs['add_time'] = int(time.time())
|
|
|
- AlexaPush.objects.create(**kwargs)
|
|
|
- # 请求Alexa服务器发送 ObjectDetection 或 Snapshot 事件
|
|
|
+ uid: str = kwargs['uid']
|
|
|
+ try:
|
|
|
+ now_time: int = int(time.time())
|
|
|
+ kwargs['add_time']: int = now_time
|
|
|
+ AlexaPush.objects.create(**kwargs)
|
|
|
+
|
|
|
+ # 请求Alexa服务器发送 ObjectDetection 或 Snapshot 事件
|
|
|
+ url: str = ALEXA_DOMAIN + 'snapshot/asynEventResponse'
|
|
|
+ storage_location: str = kwargs['storage_location']
|
|
|
+ bucket: str = 'foreignpush'
|
|
|
+ redis_obj: RedisObject = RedisObject()
|
|
|
+ obj_name: str = '{}/{}/{}.jpeg'.format(uid, kwargs['channel'], kwargs['event_time'])
|
|
|
+ image_uri: str = DevicePushService.oci_object_url(
|
|
|
+ uid=uid, redis_obj=redis_obj, storage_location=storage_location, bucket=bucket, obj_name=obj_name)
|
|
|
+ print(image_uri)
|
|
|
+ # 快照
|
|
|
+ if kwargs['event_type'] == 0:
|
|
|
+ data: Dict[str, Union[str, int]] = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'image_uri': image_uri,
|
|
|
+ 'time_sample': now_time
|
|
|
+ }
|
|
|
+ res = requests.post(url=url, data=data, timeout=30)
|
|
|
+ assert res.status_code == 200
|
|
|
+ print(res.json())
|
|
|
+ except Exception as e:
|
|
|
+ ERROR_INFO_LOGGER.info(
|
|
|
+ '发送Alexa事件线程异常,uid:{},error_line:{},error_msg:{}'.format(uid, e.__traceback__.tb_lineno, repr(e)))
|