Python-Steem Example: Follow Votes
Another example, of how I use py-steem by @xeroc.
This time I'm using the Blockchain class, that was part of steemtools by @furion.
This script will follow votes from authors in a list, called voter_list
.
Just replace pk
and account
with your posting key(s) and account(s).
Code
from steem import Steem
from steem.blockchain import Blockchain
chain = Blockchain()
voter_list = ["felixxx"]
pk = ["5GH56thyouwishlol67zPO9hkO9HKP6gthz8"]
account = ["votebot"]
steem = Steem(keys=pk[0], node="wss://node.steem.ws")
for operation in chain.ops():
op = operation["op"]
if op[0] == "vote":
#print(op) #uncomment this to get an idea of the format
comment_voter = op[1]["voter"]
if comment_voter in voter_list:
comment_link = op[1]["permlink"]
comment_author = op[1]["author"]
vote_weight = int(op[1]["weight"]/100)
comment = steem.get_post("@" + comment_author + "/" + comment_link)
if comment.is_main_post():
print("vote by: " + comment_voter + " for " + comment_link + " weight:" + str(vote_weight))
for (k,v) in enumerate(account):
try:
steem = Steem(keys=pk[k], node="wss://node.steem.ws")
comment.vote(vote_weight, v)
print("... followed with " + v + " with " + str(vote_weight) + "%")
except Exception as e:
print("... NOT followed with " + v + " because:")
print(str(e))
Known issues:
- This bot might try to cast multiple votes within too little time ( When multiple accounts in
voter_list
vote at the same time )
At the end of the day, this script does nothing more than streemian can already do.
( While streemian is more reliable )
However, I can now try out to take a vote by a trusted author to trigger an event.
Next function I will include is vote_check
, like I use for @deutschbot, to see if other trusted authors have already liked the comment, with a treshold
from 0-1.
Code
def vote_check(c_comment, curators, threshold):
votercount = 0
checked = False
check_comment = steem.get_content(c_comment.identifier)
for avote in check_comment['active_votes']:
if (avote['voter'] in curators and avote['percent'] > 0):
votercount = votercount + 1
vote_ratio = (votercount / len(curators))
if vote_ratio >= threshold:
checked = True
return checked
I post these examples, so you have some working examples of code.
Both functions are tested and work.
They are not very clever and might cause some issues, but it's something to build up on.
I don't believe curation should be done with simple algorithms.
I, personally, would maybe deploy the first script, for when I'm on holiday, so I can just follow someone I trust in his curation-efforts.
Mainly, this post is for educational purposes.
![](https://steemitimages.com/640x0/http://i.imgur.com/Bhzj9O7.png)
I would really appreciate if more people tried this out, so I have someone to talk to, when I run into problems.
I upgraded python-steem and my old bot stopped working with key errors and all sorts. Luckily I had a snapshot from weeks ago and reverted back. Think the old breed of bots will need to be rewritten :O
I'm running the latest and bot #1 above doesn't seem to work for me. No errors but it just sits there when I know it should be doing something. However, the older version I had complained about the import blockchain line. Playing around with it, it seems like it is just getting stuck at the "for operation in chain.ops():" line. I double checked my posting key and account but I'm not sure what else to try.
I'm running the winfrey bot and that seems to work ok.
There was a bug, it's fixed now.
You need to clone into the
develop
branch of py-steemI should have mentioned that above ...
try initializing Steem like this
Shouldn't it be steem = Steem(wif=[posting_key[0]])
for comment in steem.stream_comments():
I will try upgrading Steem Python again but need to set some time aside. Might just stay with this old version for a while
BTW I'm a noob at Python, this is the first time I have written in it
I'm a Python noob myself.
No, the posting_key works ok like this.
It cant be
for comment in steem.stream_comments()
I'm not trying to stream comments, but votes.
For that to work, some plugins needs to be enabled on the node.
They don't work on the default node ( at the moment )
Initialize Steem() with the "node=" argument, like I replied above.
I never did get this one to work (just hangs as far as I can tell). Upgrading to the latest Steem Python also broke the previous bot I was using so...don't do that. Unless you know how to fix it. It isn't obvious to me.
There was a bug, it's fixed now.
You need to clone into the
develop
branch of py-steem@felixxx I wish I could but I suck at programming :(
I hope you find someone who'd try this!
@felixxx
Hello. An unrelated comment.
I referred to your old post abou NiceHash here.
Still mining?
I stopped using nicehash.
I tried mining PASCAL. ( no blocks )
Now I*m not mining at all
lol, mining takes a bit to get going, I got old hardware, but it is mining.
:)