create account

Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python by steempytutorials

View this thread on: hive.blogpeakd.comecency.com
· @steempytutorials · (edited)
$22.63
Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python
<center>![steem-python.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png)</center>

This tutorial is part of a series where different aspects of programming with `steem-python` are explained. Links to the other tutorials can be found in the curriculum section below. This part is a direct continuation on [Part 3: Creating A Dynamic Autovoter That Runs 24/7](https://steemit.com/utopian-io/@steempytutorials/part-3-creating-a-dynamic-upvote-bot-that-runs-24-7-first-weekly-challenge-3-steem-prize-pool). In part 3 a dynamic automated upvoter is built that upvotes `authors` from a list with a set `upvote weight` and `total upvote` per `author` limit. The upvotes are executed directly after the post is seen on the blockchain. This part will instead add the post from the `author` to a queue and upvotes the entire queue when 100% `voting power` for the `account` is reached. 

---

#### What will I learn

- Build a queue
- Upvote a batch of posts
- Retrieve account voting power

#### Requirements

- Python3.6
- `steem-python`

#### Difficulty

- Basic

---

### Tutorial

#### Setup
Download the files from [Github](https://github.com/amosbastian/steempy-tutorials/tree/master/part_13).`batch_upvoter.py` contains the script while `upvote_list.json` is a list of author that the script will upvote.

```
author in upvote_list.json

  "steempytutorials": {
    "upvote_weight": 100,
    "upvote_limit": 1
  }
```
<br>
Run the script as normal
`> python batch_upvoter.py`


####  Build a queue
Instead of directly upvoting the post. The post will be added to a queue. The queue is a dict and for every post the `identifier` and `upvote_weight` for the given `author` are used as a pair. 

```
upvote_queue = {}

for each post:
  if post['identifier'] not in upvote_queue:
      upvote_queue[post['identifier']] = upvote_list[author]["upvote_weight"]
```


#### Upvote a batch of posts
When an upvote cycle is started all posts are taken from the dict and individually upvoted. As there is a 3 second cooldown on upvoting on the Steem blockchain after the upvote the script waits for 3 seconds.


```
for identifier in upvote_queue:
    upvote_weight = upvote_queue[identifier]
        try:
            print ("Upvoting {} for {} %".format(identifier, upvote_weight))
            steem.vote(identifier, upvote_weight, account)
            print ("Succes, sleeping for 3 seconds")
            time.sleep(3)
        except Exception as e:
            print (repr(e))
```

#### Retrieve account voting power
The `account` object contains valuable information for each account, like the current `voting power`. The standard function `voting_power()` retrieves the height of the voting power for the last upvote made by the account. To get the current voting power this function has to be replaced with the following code.

The function is located in `account.py` from `steem-Python`

```
def voting_power(self):
    diff_in_seconds = (datetime.datetime.utcnow() - parse_time(
    self["last_vote_time"])).seconds
    regenerated_vp = diff_in_seconds * 10000 / 86400 / 5
    total_vp = (self["voting_power"] + regenerated_vp) / 100
    if total_vp>100:
        return 100
    else:
        return "%.2f" % total_vp
```
[source](https://github.com/steemit/steem-python/pull/102/files)

Now the current height of the accounts `voting power` can be used to start an upvote cycle.

```
from steem.account import Account

account      = Account(account)

# start upvoting cycle at 100% voting power
if account.voting_power() == 100:
    start_upvote_cycle(upvote_queue, account)
```

#### Running the script
Set `account` to your own account. Running the script will have the program listen in on the Steem blockchain for posts made by `authors` in `upvote_list.json`. These posts are added to a queue wich is emptied when 100% `voting power` is reached. Use the standard list or alter the list to your own liking. 

![Screenshot 2018-01-24 15.51.03.png](https://steemitimages.com/DQmcL75wsoEXkp4933ce27rcwqm9sp4wLMKzAZjDM8etS29/Screenshot%202018-01-24%2015.51.03.png)


#### Curriculum
- [Part 3: Creating A Dynamic Autovoter That Runs 24/7](https://steemit.com/utopian-io/@steempytutorials/part-3-creating-a-dynamic-upvote-bot-that-runs-24-7-first-weekly-challenge-3-steem-prize-pool)
---

The code for this tutorial can be found on [GitHub](https://github.com/amosbastian/steempy-tutorials/tree/master/part_13)!

This tutorial was written by @juliank in conjunction with @amosbastian.



<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@steempytutorials/part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsteempytutorials
permlinkpart-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":84843862,"name":"steem-python","full_name":"steemit/steem-python","html_url":"https://github.com/steemit/steem-python","fork":false,"owner":{"login":"steemit"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","steemdev","python","programming","tutorial"],"users":["juliank","amosbastian"],"links":["https://steemit.com/utopian-io/@steempytutorials/part-3-creating-a-dynamic-upvote-bot-that-runs-24-7-first-weekly-challenge-3-steem-prize-pool","https://github.com/amosbastian/steempy-tutorials/tree/master/part_13","https://github.com/steemit/steem-python/pull/102/files","https://utopian.io/utopian-io/@steempytutorials/part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1515886103/kmzfcpvtzuwhvqhgpyjp.png","https://steemitimages.com/DQmcL75wsoEXkp4933ce27rcwqm9sp4wLMKzAZjDM8etS29/Screenshot%202018-01-24%2015.51.03.png"],"moderator":{"account":"fuzeh","time":"2018-01-24T20:49:45.689Z","reviewed":true,"pending":false,"flagged":false}}
created2018-01-24 16:54:15
last_update2018-01-24 20:49:45
depth0
children8
last_payout2018-01-31 16:54:15
cashout_time1969-12-31 23:59:59
total_payout_value18.188 HBD
curator_payout_value4.438 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,750
author_reputation31,094,047,689,691
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,970,574
net_rshares2,796,000,000,029
author_curate_reward""
vote details (21)
@aletepam ·
Postingan perfeck
properties (22)
authoraletepam
permlinkre-steempytutorials-2018124t235737242z
categoryutopian-io
json_metadata{"tags":["utopian-io","steemdev","python","programming","tutorial"],"app":"esteem/1.5.0","format":"markdown+html","community":"esteem"}
created2018-01-24 16:57:39
last_update2018-01-24 16:57:39
depth1
children0
last_payout2018-01-31 16:57: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_reputation20,802,115,456
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries
0.
accountesteemapp
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id31,971,226
net_rshares0
@crokkon · (edited)
.
.
properties (22)
authorcrokkon
permlinkre-steempytutorials-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180125t131525237z
categoryutopian-io
json_metadata"{"app": ""}"
created2018-01-25 13:15:24
last_update2022-09-19 18:17:57
depth1
children0
last_payout2018-02-01 13:15:24
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_length1
author_reputation81,214,366,861,104
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,199,540
net_rshares0
@fuzeh ·
Thank you for the contribution. It has been approved.

You can contact us on [Discord](https://discord.gg/uTyJkNm).
**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
authorfuzeh
permlinkre-steempytutorials-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180124t205000697z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-01-24 20:49:54
last_update2018-01-24 20:49:54
depth1
children0
last_payout2018-01-31 20:49:54
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_length172
author_reputation6,030,696,873,091
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,016,209
net_rshares0
@herryazmi11 ·
Perfeck post @steempytutorial...Introductions i am  @crokkon
properties (22)
authorherryazmi11
permlinkre-steempytutorials-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180125t140150603z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["crokkon"],"app":"steemit/0.1"}
created2018-01-25 14:02:03
last_update2018-01-25 14:02:03
depth1
children0
last_payout2018-02-01 14:02:03
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_length60
author_reputation2,332,956,252,722
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,210,303
net_rshares0
@isnamahyazani ·
useful info I will resteem let my friends can join.
properties (22)
authorisnamahyazani
permlinkre-steempytutorials-2018125t215318655z
categoryutopian-io
json_metadata{"tags":["utopian-io","steemdev","python","programming","tutorial"],"app":"esteem/1.5.0","format":"markdown+html","community":"esteem"}
created2018-01-25 14:53:21
last_update2018-01-25 14:53:21
depth1
children0
last_payout2018-02-01 14:53: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_length51
author_reputation10,633,623,304
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries
0.
accountesteemapp
weight500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,221,323
net_rshares0
@nanobot ·
This post has been upvoted for free by @nanobot with 5%! 
 Get better upvotes by bidding on me.
properties (22)
authornanobot
permlinkre-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180124t205414
categoryutopian-io
json_metadata""
created2018-01-24 20:54:00
last_update2018-01-24 20:54:00
depth1
children2
last_payout2018-01-31 20:54:00
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_length95
author_reputation102,775,974,122
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id32,016,945
net_rshares0
@phoxinus ·
!LUV
properties (22)
authorphoxinus
permlinkre-re-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180124t205414-20220304t164330z
categoryutopian-io
json_metadata"{"app": "beem/0.24.26"}"
created2022-03-04 16:43:30
last_update2022-03-04 16:43:30
depth2
children1
last_payout2022-03-11 16:43:30
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_length4
author_reputation555,946,320,138
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id111,014,369
net_rshares0
@luvshares ·
@phoxinus<sub>(1/1)</sub> gave you LUV. <a href="https://peakd.com/@luvshares/about" style="text-decoration:none"><img src="https://files.peakd.com/file/peakd-hive/crrdlx/AKU7oyCXxGwYyudB42kJ7JtoZ63bdeHvm4icoT9xdGNxA4i4BwudGyPvTQrEwPd.gif"></a> <a
    href="https://crrdlx.websavvy.work/" style="text-decoration:none">H-E tools</a> | <a 
    href="https://discord.gg/K5GvNhcPqR" style="text-decoration:none">connect</a> | <a href="https://ichthys.netlify.app" style="text-decoration:none"><><</a>
<br><small>LUV level requirements were changed. See the <a href="https://peakd.com/luv/@luvshares/about">About</a> page for current numbers.</small>
properties (22)
authorluvshares
permlinkre-re-re-part-13-upvote-posts-in-batches-based-on-current-voting-power-with-steem-python-20180124t205414-20220304t164330z-20220304t164436z
categoryutopian-io
json_metadata"{"app": "beem/0.24.26"}"
created2022-03-04 16:44:36
last_update2022-03-04 16:44:36
depth3
children0
last_payout2022-03-11 16:44: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_length645
author_reputation5,651,102,754,153
root_title"Part 13: Upvote Posts In Batches Based On Current Voting Power With Steem-Python"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id111,014,391
net_rshares0