slowly making it more better
parent
7c66c9eaf2
commit
155a0f7f14
|
@ -561,29 +561,46 @@ class Camera(Device):
|
||||||
"Accept": "application/json"
|
"Accept": "application/json"
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.get(url, headers=headers)
|
try:
|
||||||
response_json = response.json()
|
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.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.info(f"{response.status_code} in get_list_of_events")
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
success = True
|
success = True
|
||||||
# filter events by type
|
# filter events by type
|
||||||
[self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1']
|
[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']
|
[self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1']
|
||||||
|
|
||||||
# remove duplicates
|
# remove duplicates
|
||||||
seen = set()
|
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'])]
|
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()
|
seen = set()
|
||||||
self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])]
|
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
|
# sort by event startTimestamp descending
|
||||||
self.events['status'] = sorted(self.events['status'], key=lambda x: x['startTimestamp'], reverse=True)
|
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)
|
self.events['motion'] = sorted(self.events['motion'], key=lambda x: x['startTimestamp'], reverse=True)
|
||||||
else:
|
else:
|
||||||
success = False
|
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 {
|
return {
|
||||||
|
|
2
app.py
2
app.py
|
@ -122,7 +122,7 @@ def camera_live_preivew(esn=None):
|
||||||
if res:
|
if res:
|
||||||
return send_file(BytesIO(res.content), mimetype='image/jpeg')
|
return send_file(BytesIO(res.content), mimetype='image/jpeg')
|
||||||
else:
|
else:
|
||||||
return send_file('static/placeholder1.png')
|
return send_file('static/placeholder.png')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/camera/<esn>')
|
@app.route('/camera/<esn>')
|
||||||
|
|
|
@ -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>
|
<h3>Online</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for camera in template_values['cameras'] %}
|
{% for camera in template_values['cameras'] %}
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block style %}
|
{% block style %}
|
||||||
|
<style>
|
||||||
|
#camera_list_items {
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#events_list {
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block current_user %}
|
{% block current_user %}
|
||||||
|
|
Loading…
Reference in New Issue