-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
43 lines (33 loc) · 1.25 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
import os
from flask import Flask
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:////tmp/test.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Transaction(db.Model):
id = db.Column(db.Integer, primary_key=True)
hash_id = db.Column(db.String(64), unique=True)
sender = db.Column(db.String(35))
block_height = db.Column(db.Integer)
time = db.Column(db.DateTime)
amount = db.Column(db.BigInteger)
usd_worth = db.Column(db.Float)
def __init__(self, hash_id, sender, block_height, time, amount, usd_worth):
self.hash_id = hash_id
self.sender = sender
self.block_height = block_height
self.time = time
self.amount = amount
self.usd_worth = usd_worth
def __repr__(self):
return '<Transaction %r>' % self.hash_id
@app.route('/')
def home():
txs = Transaction.query.all()
total_usd = sum([tx.usd_worth for tx in txs])
return render_template('index.html', txs=txs, total_usd=total_usd)
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port, debug=True)