-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (36 loc) · 1.06 KB
/
app.py
File metadata and controls
43 lines (36 loc) · 1.06 KB
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
from flask import Flask, render_template, jsonify, request
import sqlite3
app = Flask(__name__)
def get_db():
return sqlite3.connect("ci.db")
@app.route("/")
def home():
return render_template("index.html")
@app.route("/api/stats")
def stats():
conn = get_db()
c = conn.cursor()
total = c.execute("SELECT COUNT(*) FROM failures").fetchone()[0]
last = c.execute("SELECT message FROM failures ORDER BY id DESC LIMIT 1").fetchone()
conn.close()
return jsonify({
"total": total,
"last": last[0] if last else "No failures yet"
})
@app.route("/api/logs")
def logs():
conn = get_db()
c = conn.cursor()
data = c.execute("SELECT message FROM failures ORDER BY id DESC LIMIT 10").fetchall()
conn.close()
return jsonify(data)
@app.route("/api/failure", methods=["POST"])
def add_failure():
msg = request.json["message"]
conn = get_db()
c = conn.cursor()
c.execute("INSERT INTO failures(message) VALUES (?)", (msg,))
conn.commit()
conn.close()
return {"status":"ok"}
app.run(debug=True)