forked from yippymishy/BlockBit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
36 lines (29 loc) · 972 Bytes
/
api.py
File metadata and controls
36 lines (29 loc) · 972 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
from flask import Flask, jsonify, abort, render_template
from local_simple_database import LocalDictDatabase
# Setup database
LDD = LocalDictDatabase(str_path_database_dir=".", default_value=None)
db = LDD["dict_balances"]
notifications_db = LDD["dict_notifcations"]
transactions_db = LDD["dict_transactions"]
# Flask stuff
app = Flask(__name__)
# Main route
@app.route('/')
def home():
return render_template('index.html')
@app.route('/query/<username>')
def query_user(username):
result = {}
for k,v in transactions_db.items():
if v["from"] == username or v["to"] == username:
result.update({k:v})
return result
@app.route('/balance/<username>')
def balance(username):
try:
balance = db[username]
return jsonify({'success': True, 'username': username, 'balance': balance})
except KeyError:
return jsonify({'success': False, 'message': 'User not found'})
if __name__ == '__main__':
app.run()