Skip to content

Instantly share code, notes, and snippets.

@singhpratyush
Created October 30, 2018 12:34
Show Gist options
  • Save singhpratyush/842d2d1f1f94e6f25001c8fcda1dde33 to your computer and use it in GitHub Desktop.
Save singhpratyush/842d2d1f1f94e6f25001c8fcda1dde33 to your computer and use it in GitHub Desktop.
Steem Resource Credits for a User
import beem
from datetime import datetime
def get_resource_credits(username):
client = beem.Steem()
rc = beem.rc.RC(steem_instance=client)
account = beem.account.Account(username).json()
comment_requirement = rc.comment()
vote_requirement = rc.vote()
transfer_requirement = rc.transfer()
current_time = client.get_dynamic_global_properties()['time']
current_time_utc = int(datetime.timestamp(datetime.strptime(current_time, '%Y-%m-%dT%H:%M:%S')))
elapsed_time = current_time_utc - float(account['voting_manabar']['last_update_time'])
total_shares = float(account['vesting_shares']['amount']) / 10.0 ** account['vesting_shares']['precision'] \
+ float(account['received_vesting_shares']['amount']) / 10.0 ** account['received_vesting_shares']['precision'] \
- float(account['delegated_vesting_shares']['amount']) / 10.0 ** account['delegated_vesting_shares']['precision']
max_mana = total_shares * 1000000
current_mana = float(account['voting_manabar']['current_mana']) + elapsed_time * max_mana / 432000
print(current_mana)
if current_mana > max_mana:
current_mana = max_mana
current_mana_percentage = current_mana * 100 / max_mana
return {
'total_shares': total_shares,
'blockchain_time': current_time_utc,
'current_mana': current_mana,
'max_mana': max_mana,
'comment_requirement': comment_requirement,
'vote_requirement': vote_requirement,
'transfer_requirement': transfer_requirement,
'comment_count': current_mana // comment_requirement,
'vote_count': current_mana // vote_requirement,
'transfer_count': current_mana // transfer_requirement,
'percentage': current_mana_percentage,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment