Update views.py

This commit is contained in:
Arc 2020-02-26 00:40:42 +00:00 committed by GitHub
parent 4bfa9a6a05
commit d22ef892a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,8 @@ def index():
"""Try to add descriptions for others.""" """Try to add descriptions for others."""
usr = request.args.get("usr") usr = request.args.get("usr")
nme = request.args.get("nme") nme = request.args.get("nme")
wal = request.args.get("wal")
cur = request.args.get("cur")
if usr: if usr:
if not len(usr) > 20: if not len(usr) > 20:
@ -21,6 +23,7 @@ def index():
# Get all the data # Get all the data
with open_db() as db: with open_db() as db:
user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,)) user_wallets = db.fetchall("SELECT * FROM wallets WHERE user = ?", (usr,))
user_wall = db.fetchall("SELECT * FROM wallets WHERE user = ? AND id = ?", (usr,wal))
user_ext = db.fetchall("SELECT extension FROM extensions WHERE user = ? AND active = 1", (usr,)) user_ext = db.fetchall("SELECT extension FROM extensions WHERE user = ? AND active = 1", (usr,))
user_ext = [v[0] for v in user_ext] user_ext = [v[0] for v in user_ext]
@ -30,20 +33,21 @@ def index():
pos_ext_db.execute( pos_ext_db.execute(
""" """
INSERT OR IGNORE INTO tpos INSERT OR IGNORE INTO tpos
(nme, uni, usr, invkey) (nme, uni, usr, invkey, cur)
VALUES (?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
""", """,
( (
nme, nme,
uni, uni,
usr, usr,
user_wallets[0][3], user_wall[0][3],
cur,
), ),
) )
with open_ext_db("tpos") as pos_ext_dbb: with open_ext_db("tpos") as pos_ext_dbb:
user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE usr = ?", (usr,)) user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE usr = ?", (usr,))
return render_template( return render_template(
"tpos/index.html", user_wallets=user_wallets, user_ext=user_ext, usr=usr, user_fau=user_fau "tpos/index.html", user_wallets=user_wallets, user_ext=user_ext, usr=usr, user_fau=user_fau
) )
@ -52,13 +56,15 @@ def index():
def tpos(): def tpos():
"""Try to add descriptions for others.""" """Try to add descriptions for others."""
pos = request.args.get("pos") pos = request.args.get("pos")
exc = request.args.get("exc")
with open_ext_db("tpos") as pos_ext_dbb: with open_ext_db("tpos") as pos_ext_dbb:
user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE uni = ?", (pos,)) user_fau = pos_ext_dbb.fetchall("SELECT * FROM tpos WHERE uni = ?", (pos,))
if not user_fau: if not user_fau:
return jsonify({"status": "ERROR", "reason":"NO POS"}), 400 return jsonify({"status": "ERROR", "reason":"NO POS"}), 400
r = requests.get("https://api.opennode.co/v1/rates")
r_json = r.json()
return render_template( return render_template(
"tpos/tpos.html", pos=pos, exchange=exc "tpos/tpos.html", pos=pos, exchange=int(r_json["data"]["BTC" + user_fau[0][5]][user_fau[0][5]])
) )