-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (59 loc) · 2.19 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# save this as app.py
from flask import Flask, render_template
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
import xmltodict
import time
from datetime import datetime
from collections import OrderedDict
app = Flask(__name__)
auth = HTTPBasicAuth()
users = {
"admin": generate_password_hash("SOMERANDOMPASSWORD"),
}
@auth.verify_password
def verify_password(username, password):
if username in users and \
check_password_hash(users.get(username), password):
return username
@app.route("/")
@auth.login_required
def index():
with open('/tmp/recordings.xml', 'r') as f:
raw = f.readlines()
data = xmltodict.parse(''.join([x.strip() for x in raw]))
if data['response']['returncode'] == 'SUCCESS':
rawrecords = data['response']['recordings']['recording']
records = list()
for r in rawrecords:
name = r['name']
ts = int(r['startTime'][:-3])
date = datetime.fromtimestamp(ts).strftime('%d.%m.%Y')
stime = datetime.fromtimestamp(ts).strftime('%H:%M:%S')
duration_raw = int(r['playback']['format']['length'])
duration = time.strftime("%H:%M:%S", time.gmtime(duration_raw * 60))
url = r['playback']['format']['url']
previews = r['playback']['format']['preview']['images']['image']
if type(previews) is list:
preview = previews[0]['#text']
elif type(previews) is OrderedDict:
preview = previews['#text']
else:
print(r)
continue
d = {
'name': name,
'timestamp': ts,
'date': date,
'time': stime,
'duration_raw': duration_raw,
'duration': duration,
'url': url,
'preview': preview,
}
records.append(d)
records = sorted(records, key=lambda x: x['timestamp'], reverse=True)
return render_template("bootstrap_table.html", title='Recording list',
records=records)
if __name__ == '__main__':
app.run()