How to get a value from SQLite to convert it?

0 votes

So I have an issue, I am trying to convert a float value from SQLite Db. The value represents a price in USD and I want to convert it in BTC, I was installing python-forex but because I do not have experience enough I am stack on this:

b = BtcConverter(force_decimal=True)
p = float(acf1.p1)
pbtc = b.convert_to_btc(10, 'USD')

What I need to do is to exchange "10" with "p", and "p" is a row from my SQlite Db.

I was trying to get acfi.p1 from db table with:

acf1 = KAch.query.order_by(KAch.reg.desc()).all()

As well the html code is:

{{ "%.9f" %pbtc }}

But because I am new is giving me 500 error.

Code:

@app.route('/adfa', methods=['GET', 'POST'])
def add_foa():
    t1=request.form.get('t1')
    c1=request.form.get('c1')
    p1=request.form.get('p1')
    p2=request.form.get('p2')
    um1=request.form.get('um1')
    ce1=request.form.get('ce1')
    dc1=request.form.get('dc1')
    mdla1=request.form.get('mdla1')
    mdam1=request.form.get('mdam1')
    aop=request.form.get('aop')
    pz1=request.form.get('pz1')
    users_id = request.form.get('users_id')

    acf1 = KAch(
                t1=t1,
                c1=c1,
                p1=p1,
                p2=p2,
                um1=um1,
                ce1=ce1,
                dc1=dc1,
                mdla1=mdla1,
                mdam1=mdam1,
                aop=aop,
                pz1=pz1,
                users_id=current_user.id,
                reg=datetime.now())

    db.session.add(acf1)
    db.session.commit()

    return redirect(url_for('adfa', users_id=current_user.id, _external=True))

@app.route('/profil/<int:users_id>')
@login_required
def profil(users_id):
    ac1 = KAch.query.order_by(KAch.reg.desc()).all()
    user = User.query.filter_by(id=users_id).first()
    profil1 = KProfil.query.filter_by(id=users_id).one()

    b = BtcConverter(force_decimal=True)
    #p = float(acf1.p1)
    pbtc = b.convert_to_btc(10, 'USD')

    if 'out' in current_user.tc:
        return redirect(url_for('adpro', users_id=current_user.id, _external=True))
    elif 'n' in current_user.tc:
        return redirect(url_for('logout', _external=True))

    return render_template('front/usr/usr.html', profil1=profil1, user=user, ac1=ac1, pbtc=pbtc)
Sep 6, 2018 in Blockchain by slayer
• 29,040 points
22 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Server side:

b = BtcConverter(force_decimal=True)
p1btc = b.get_latest_price('USD')
p1btcr = b.get_latest_price('RON')
pbtc = b.convert_to_btc(10, 'USD')
pron = float(Decimal(p1btcr))

HTML side:

{{ acf1.p1 / pron }}
answered Sep 6, 2018 by digger
• 27,620 points

Related Questions In Blockchain

+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 16,450 points
596 views
0 votes
1 answer

How to get return value from solidity contract?

Once you call a constant function, you ...READ MORE

answered Aug 16, 2018 in Blockchain by slayer
• 29,040 points
292 views
0 votes
2 answers
0 votes
1 answer

How to get value from solidity contract using java?

web3j caters for this very use case. It ...READ MORE

answered Sep 28, 2018 in Blockchain by slayer
• 29,040 points
116 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by ariaholic
• 7,320 points
43 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
64 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to get all address and send ethers in solidity using a loop?

I found a similar code somewhere: contract  Holders{ uint ...READ MORE

answered Jul 31, 2018 in Blockchain by digger
• 27,620 points
95 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.