-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
39 lines (33 loc) · 1.14 KB
/
server.py
File metadata and controls
39 lines (33 loc) · 1.14 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
from flask import Flask, render_template, jsonify
import sqlite3
import time
app = Flask(__name__)
SECONDS = 3600 * 24 * 7
def get_table(c, table_name) -> list:
now = int(time.time())
c.execute(f"SELECT * FROM {table_name} WHERE time >= {now - SECONDS}");
return c.fetchall()
def get_all_data(c) -> str:
return jsonify({
"totalBalnSupply": get_table(c, "totalBalnSupply"),
"stakedBalnSupply": get_table(c, "stakedBalnSupply"),
"balnBnusdPrice": get_table(c, "balnBnusdPrice"),
"sicxBnusdPrice": get_table(c, "sicxBnusdPrice"),
"balnSicxPrice": get_table(c, "balnSicxPrice"),
"sicxIcxPool": get_table(c, "sicxIcxPool"),
"sicxBnusdPool": get_table(c, "sicxBnusdPool"),
"balnBnusdPool": get_table(c, "balnBnusdPool"),
"balnBnusdApy": get_table(c, "balnBnusdApy"),
"sicxBnusdApy": get_table(c, "sicxBnusdApy"),
"sicxIcxApy": get_table(c, "sicxIcxApy"),
"loansApy": get_table(c, "loansApy"),
})
@app.route('/readall')
def readall():
conn = sqlite3.connect('./baln.db')
data = get_all_data(conn.cursor())
conn.close()
return data
@app.route('/')
def index():
return render_template('index.jinja')