Python Beem Project: Account Information Part 5

in #python2 months ago

I have updated my project a bit.
It is kind of nice to know how HIVE and STEEM are doing so I took some chart widgets from CoinGecko and added to my home page.
Also I have added a "Profile" thing that you can check your account information.
Reputation, voting power, wallet info and delegations.

UI, layout stuff will probably change again soon since I am going to add information in this page, but it is a nice start.
Design inspirations came from and that I use time to time but I don't use all the features.
I just want some specific information and display it in my way but I like hivestats' clean design so I think it will probably end up looking like to hivestat 🤣
Hopefully able to add some nice touch to it though 🙈 🙊 🙉

Main stuff I added was like this 👇

@app.route('/hive/profile', methods=['GET', 'POST'])
def hive_profile():
    form = UserNameForm(request.form)

    if request.method == 'POST':
        if form.validate():
            username = request.form['username'].lower()

            return redirect('/hive/profile/' + username)
            flash('Username is Required')

    return render_template('hive/profile.html', form=form)

def hive_profile_data(username=None):
    data = {}
    if username:
        username = escape(username).lower()
        data = get_user_profile('hive', username)

    if data:
        return render_template('hive/profile_data.html',
                               username=username, data=data)
        return render_template('hive/profile_data.html',
                               username=None, data=data)
def get_user_profile(chain_type, username):
    chain = None
    if chain_type == 'hive':
        chain = set_node_list(chain_type='hive')
    elif chain_type == 'steemit':
        chain = set_node_list(chain_type='steemit')
        return None

    # Create account object
        account = Account(username)
    except Exception as e:
        return None

    profile = account.profile

    profile['balances'] = account.get_balances()
    profile['voting_power'] = f"{account.get_voting_power(): .2f}"
    profile['reputation'] = f"{account.get_reputation(): .1f}"

    token_power = account.get_token_power()
    profile['token_power'] = f"{token_power:.3f}"

    # Get delegations
    delegations = account.get_vesting_delegations()
    if delegations:
        profile['delegations'] = get_user_delegations(
            chain, username, delegations)
        profile['delegations'] = []

    return profile
def get_user_delegations(chain, username, delegations):
    # Convert vest to power
    delegation_list = []
    for d in delegations:
        amount = d['vesting_shares']['amount']
        precision = d['vesting_shares']['precision']
        precision = 10 ** precision
        delegatee = d['delegatee']
        vest_amount = float(int(amount) / precision)
        if chain.is_hive:
            delegation_power = f"{chain.vests_to_hp(vest_amount):.3f}"
        elif chain.is_steem:
            delegation_power = f"{chain.vests_to_sp(vest_amount):.3f}"

            {'delegatee': delegatee, 'amount': delegation_power})

    return delegation_list

My stuff is all in here if you like to look at it.
(please dont. it is a big mess right now lol)

Get Rewarded For Browsing! Are you Brave?

happy tears
➡️ Website
➡️ Twitter

Coin Marketplace

STEEM 0.17
TRX 0.03
JST 0.037
BTC 10765.90
ETH 356.49
USDT 1.00
SBD 0.96