create account

steem-python tips #1 - Calculating power-ups! by emrebeyler

View this thread on: hive.blogpeakd.comecency.com
· @emrebeyler · (edited)
$61.73
steem-python tips #1 - Calculating power-ups!
<img src="https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drxhdemuq4r4ezSCFC6xhAknvQspB_1680x8400">

#### Powering up
***

Powering up is a process on steem blockchain where you convert your liquid STEEMs to Steem Power. Every time an account powers up, it broadcast a "transfer_to_vesting" operation to the network.

@sndbox and some other organizations have weekly power-up challenges. And I was lucky to win a couple of them. Today I was curious how much I have powered up in the last month. (I did powered-up a lot.)

#### Filtering "transfer\_to\_vesting" ops with steem-python
***

Out script's main flow should be like this:

- Get an input with username, start_date, and end_date
- Filter all "transfer\_to\_vesting" operations between start_date and end_date
- Sum all powered-up amount in corresponding transactions.

And we have the number.

*Basic example to filter specific operations:*

```
from steem import Steem
from steem.account import Account
s = Steem(nodes=["https://api.steemit.com"])
acc = Account('emrebeyler', steemd_instance=s)
for op in acc.history_reverse(filter_by=["transfer_to_vesting"]):
    print(op)
```    
    
This script will filter all "transfer\_to\_vesting" operations in your **entire** account history and prints them.

#### The Calculator script
***

```python
from steem import Steem
from steem.account import Account
from steem.amount import Amount
from dateutil.parser import parse
from datetime import datetime
import tableprint as tp
def calculate_powerup(username, start_date, end_date):
    s = Steem(nodes=["https://api.steemit.com"])
    account = Account(username, steemd_instance=s)
    data = []
    total = 0
    for op in account.history_reverse(filter_by=["transfer_to_vesting"]):
        ts = parse(op["timestamp"])
        if ts > end_date:
            continue
        if ts < start_date:
            break
        total += Amount(op["amount"]).amount
        data.append((op["amount"], op["timestamp"]))
    data.append(("Total: %s STEEM" % round(total, 2), "-"))
    return data, total
if __name__ == '__main__':
    data, total = calculate_powerup(
        'emrebeyler',
        datetime(2018, 2, 1),
        datetime(2018, 3, 1),
    )
    tp.table(data, ['Amount', 'Timestamp'], width=32)
```

#### Example output
****

![Screen Shot 2018-03-01 at 14.29.50.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519903918/aldpmg7pblf2uc5ij1ec.png)
<center><sup>Seems like I was good powering-up on February!</sup></center>

***

You can play with other accounts and timeframes by changing start_date and end_date. Make sure you have steem-python and tableprint libraries installed on your local environment. 

Have fun.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 67 others
properties (23)
authoremrebeyler
permlinksteem-python-tips-1-calculating-power-ups
categorypython
json_metadata{"community":"busy","app":"busy/2.4.0","format":"markdown","tags":["python","steem-python","steem","sndbox","busy"],"users":["sndbox"],"links":["/@sndbox"],"image":["https://steemitimages.com/0x0/https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/U5drxhdemuq4r4ezSCFC6xhAknvQspB_1680x8400","https://steemitimages.com/0x0/https://res.cloudinary.com/hpiynhbhq/image/upload/v1519903918/aldpmg7pblf2uc5ij1ec.png"]}
created2018-03-01 11:36:30
last_update2018-03-01 11:45:45
depth0
children14
last_payout2018-03-08 11:36:30
cashout_time1969-12-31 23:59:59
total_payout_value53.481 HBD
curator_payout_value8.251 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,708
author_reputation448,535,049,068,622
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,360,264
net_rshares11,806,145,860,444
author_curate_reward""
vote details (131)
@appreciator ·
re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t115806017z
This post has received gratitude of 5.80% from @appreciator courtesy of @emrebeyler!
properties (22)
authorappreciator
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t115806017z
categorypython
json_metadata{"app":"postpromoter/1.8.7"}
created2018-03-01 11:58:06
last_update2018-03-01 11:58:06
depth1
children0
last_payout2018-03-08 11:58:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation55,801,543,512,306
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,364,266
net_rshares0
@jeffbernst ·
$0.05
This is awesome! Do you know if there's something similar in Steem.js? I couldn't find a way to target the power up transactions specifically, so when I made the power up calcuator for sndbox I ended up having to just make an API call for a big slice of a user's transactions and then filter out the ones that were power ups.
👍  ,
properties (23)
authorjeffbernst
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t144216039z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 14:42:15
last_update2018-03-01 14:42:15
depth1
children2
last_payout2018-03-08 14:42:15
cashout_time1969-12-31 23:59:59
total_payout_value0.047 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length325
author_reputation13,041,257,634,850
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,398,313
net_rshares9,526,728,269
author_curate_reward""
vote details (2)
@emrebeyler ·
$0.06
Actually, this is the same w/ python. It's a syntactic sugar that just filters while browsing all type of transactions.

 I remember a feature request at Github asking if filtering can be done on the steem daemon itself but it's not there yet.
👍  
properties (23)
authoremrebeyler
permlinkre-jeffbernst-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t144638487z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 14:46:39
last_update2018-03-01 14:46:39
depth2
children1
last_payout2018-03-08 14:46:39
cashout_time1969-12-31 23:59:59
total_payout_value0.053 HBD
curator_payout_value0.003 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length243
author_reputation448,535,049,068,622
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,399,334
net_rshares11,358,312,584
author_curate_reward""
vote details (1)
@jeffbernst ·
Ah ok, yeah I found a feature request for Steem.js about that feature too. Super cool what you did here though! I keep getting more curious about Python :P
properties (22)
authorjeffbernst
permlinkre-emrebeyler-re-jeffbernst-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t145943231z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 14:59:42
last_update2018-03-01 14:59:42
depth3
children0
last_payout2018-03-08 14:59:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length155
author_reputation13,041,257,634,850
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,402,067
net_rshares0
@kalvas ·
$0.04
woah nice one
👍  
properties (23)
authorkalvas
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t114209792z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 11:42:12
last_update2018-03-01 11:42:12
depth1
children2
last_payout2018-03-08 11:42:12
cashout_time1969-12-31 23:59:59
total_payout_value0.034 HBD
curator_payout_value0.006 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length13
author_reputation212,163,488,056,788
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,361,354
net_rshares8,419,180,407
author_curate_reward""
vote details (1)
@emrebeyler ·
did you start learning python?
properties (22)
authoremrebeyler
permlinkre-kalvas-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t120332686z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 12:03:33
last_update2018-03-01 12:03:33
depth2
children1
last_payout2018-03-08 12:03:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length30
author_reputation448,535,049,068,622
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,365,300
net_rshares0
@kalvas ·
Yeah I started you are my idol thanks for sharing
properties (22)
authorkalvas
permlinkre-emrebeyler-re-kalvas-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t121135275z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 12:11:36
last_update2018-03-01 12:11:36
depth3
children0
last_payout2018-03-08 12:11:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length49
author_reputation212,163,488,056,788
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,366,874
net_rshares0
@teamhumble ·
$0.04
you put out some awesome stuff man. thanks for everything you do! :)
👍  
properties (23)
authorteamhumble
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t130050046z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 13:00:51
last_update2018-03-01 13:00:51
depth1
children0
last_payout2018-03-08 13:00:51
cashout_time1969-12-31 23:59:59
total_payout_value0.030 HBD
curator_payout_value0.009 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length68
author_reputation315,232,864,758,316
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,376,510
net_rshares8,419,307,482
author_curate_reward""
vote details (1)
@themarkymark · (edited)
You should add a check for your account, it isn't common but you can power up another account and they will show up as `transfer_to_vesting` so your script will factor them in as local power-ups.

It's kind of an edge case but I use it a lot.
properties (22)
authorthemarkymark
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180304t195800479z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-04 19:57:57
last_update2018-03-04 19:58:15
depth1
children1
last_payout2018-03-11 19:57:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length242
author_reputation1,778,537,845,749,984
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,204,676
net_rshares0
@emrebeyler ·
True! I did that a couple of times actually. Thanks for the heads up.
properties (22)
authoremrebeyler
permlinkre-themarkymark-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180304t195947749z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-04 19:59:48
last_update2018-03-04 19:59:48
depth2
children0
last_payout2018-03-11 19:59:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length69
author_reputation448,535,049,068,622
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id42,205,008
net_rshares0
@ulqu3 ·
Whoa, creativity.
properties (22)
authorulqu3
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t113734434z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 11:37:39
last_update2018-03-01 11:37:39
depth1
children0
last_payout2018-03-08 11:37:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length17
author_reputation43,754,280,289,730
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,360,469
net_rshares0
@ulul44 ·
Yeah nice guys
properties (22)
authorulul44
permlinkre-emrebeyler-201831t183811308z
categorypython
json_metadata{"tags":["python","steem-python","steem","sndbox","busy"],"app":"esteem/1.5.1","format":"markdown+html","community":"esteem"}
created2018-03-01 11:38:12
last_update2018-03-01 11:38:12
depth1
children0
last_payout2018-03-08 11:38:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation3,144,655,345
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries
0.
accountesteemapp
weight1,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,360,567
net_rshares0
@zorto ·
$0.04
That's my pythonman 😎
👍  
properties (23)
authorzorto
permlinkre-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t124401161z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 12:43:48
last_update2018-03-01 12:43:48
depth1
children1
last_payout2018-03-08 12:43:48
cashout_time1969-12-31 23:59:59
total_payout_value0.038 HBD
curator_payout_value0.003 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length21
author_reputation1,380,371,663,915
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,373,151
net_rshares8,419,240,471
author_curate_reward""
vote details (1)
@emrebeyler ·
Grazie, Zorto.
properties (22)
authoremrebeyler
permlinkre-zorto-re-emrebeyler-steem-python-tips-1-calculating-power-ups-20180301t124421797z
categorypython
json_metadata{"tags":["python"],"app":"steemit/0.1"}
created2018-03-01 12:44:21
last_update2018-03-01 12:44:21
depth2
children0
last_payout2018-03-08 12:44:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation448,535,049,068,622
root_title"steem-python tips #1 - Calculating power-ups!"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id41,373,266
net_rshares0