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,370 points
682 views

1 answer to this question.

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
• 26,740 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
• 17,100 points
2,894 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,370 points
4,965 views
0 votes
2 answers

Is it possible to modify a variable value from another contract?

No, you can't directly edit a variable ...READ MORE

answered Sep 24, 2018 in Blockchain by Sai
4,268 views
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,370 points
1,963 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,327 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
1,882 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,399 views
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
• 26,740 points
2,724 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP