-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (33 loc) · 907 Bytes
/
Copy pathserver.py
File metadata and controls
37 lines (33 loc) · 907 Bytes
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
import os
import sqlite3
import json
from flask import Flask, render_template, jsonify
from datetime import datetime
app = Flask(__name__)
DB_PATH = "/data/eflog.db"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/logs.json")
def logs():
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
try:
cursor.execute("SELECT timestamp, status_code, data FROM status_log")
rows = cursor.fetchall()
result = []
for ts, status, raw in rows:
try:
data = json.loads(raw.replace("'", """))
except:
data = {}
result.append({
"timestamp": ts,
"status": status,
"data": data
})
return jsonify(result)
finally:
conn.close()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)