slowly making it more better

full_example
Mark Cotton 2023-07-14 10:48:14 -05:00
parent 7c66c9eaf2
commit 155a0f7f14
4 changed files with 50 additions and 21 deletions

View File

@ -561,29 +561,46 @@ class Camera(Device):
"Accept": "application/json"
}
response = requests.get(url, headers=headers)
response_json = response.json()
try:
response = requests.get(url, headers=headers, timeout=(3, 5))
response_json = response.json()
logging.debug(f"{response.status_code} returned from {url} with {headers} and {response.text}")
logging.info(f"{response.status_code} in get_list_of_events")
logging.debug(f"{response.status_code} returned from {url} with {headers} and {response.text}")
logging.info(f"{response.status_code} in get_list_of_events")
if response.status_code == 200:
success = True
# filter events by type
[self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1']
[self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1']
if response.status_code == 200:
success = True
# filter events by type
[self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1']
[self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1']
# remove duplicates
seen = set()
self.events['status'] = [event for event in self.events['status'] if event['endTimestamp'] and event['id'] not in seen and not seen.add(event['id'])]
seen = set()
self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])]
# remove duplicates
seen = set()
self.events['status'] = [event for event in self.events['status'] if event['endTimestamp'] and event['id'] not in seen and not seen.add(event['id'])]
seen = set()
self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])]
# sort by event startTimestamp descending
self.events['status'] = sorted(self.events['status'], key=lambda x: x['startTimestamp'], reverse=True)
self.events['motion'] = sorted(self.events['motion'], key=lambda x: x['startTimestamp'], reverse=True)
else:
success = False
# sort by event startTimestamp descending
self.events['status'] = sorted(self.events['status'], key=lambda x: x['startTimestamp'], reverse=True)
self.events['motion'] = sorted(self.events['motion'], key=lambda x: x['startTimestamp'], reverse=True)
else:
success = False
except requests.exceptions.Timeout:
logging.warn(f"timeout expired for {self.id} get_llist_of_events()")
return {
"success": False,
"response_http_status": 0,
"data": None
}
except requests.exceptions.RequestException as e:
logging.warn(e)
return {
"success": False,
"response_http_status": 0,
"data": None
}
return {

2
app.py
View File

@ -122,7 +122,7 @@ def camera_live_preivew(esn=None):
if res:
return send_file(BytesIO(res.content), mimetype='image/jpeg')
else:
return send_file('static/placeholder1.png')
return send_file('static/placeholder.png')
@app.route('/camera/<esn>')

View File

@ -1,6 +1,6 @@
<div class="col-md-3" id="camera_list_offline">
<div class="col-md-3" id="camera_list_items">
<h3>Online</h3>
<ul>
{% for camera in template_values['cameras'] %}

View File

@ -1,6 +1,18 @@
{% extends "base.html" %}
{% block style %}
<style>
#camera_list_items {
max-height: 500px;
overflow: auto;
}
#events_list {
max-height: 500px;
overflow: auto;
}
</style>
{% endblock %}
{% block current_user %}