Python-Steem Example: Follow Votes

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@felixxx·
0.000 HBD
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 <code>voter_list</code>.
Just replace <code>pk</code> and <code>account</code> 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 <code>voter_list</code> 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 <code>vote_check</code>, like I use for @deutschbot, to see if other trusted authors have already liked the comment, with a <code>treshold</code> 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.

<center>http://i.imgur.com/Bhzj9O7.png</center>

I would really appreciate if more people tried this out, so I have someone to talk to, when I run into problems.

# Have fun !
👍 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,