Personal Voter

in Programming & Dev3 years ago

hive.png

1 Voting for your favorites on hive automatically

So I have been fooling around with a few different bot strategies, but I think this will be the one I might use.

I want to create a bot that will just vote for a few accounts that I choose.

The way to do a vote is simple enough, and is the only thing written in python, the rest will be in hy.

        #!/usr/bin/env python
        from beem import Hive
        from beem.account import Account
        from beem.vote import ActiveVotes
        from beem.transactionbuilder import TransactionBuilder
        from beembase.operations import Vote
        import time
        client = Hive()

        def vote_for(author, permlink, weight):
                        f=open("votes.log", "a")
                        try:
                                        tx = TransactionBuilder(blockchain_instance=client)
                                        tx.appendOps(Vote(**{
                                                                        "voter": "iobates",
                                                                        "author": author,
                                                                        "permlink": permlink,
                                                                        "weight": int(float(weight) * 100)
                                        }))

                                        tx.appendWif() # Your key go here
                                        signed_tx = tx.sign()
                                        broadcast_tx = tx.broadcast(trx_id=True)

                                        f.write("Vote cast successfully: " + str(broadcast_tx))
                                        print("Vote cast successfully: " + str(broadcast_tx))
                                        f.write("\n")
                        except Exception as e:
                                                        print('\n' + str(e) + '\nException encountered.  Unable to vote' + str(time.gmtime()))
                        f.close()


That code will not do anything by itself, and I will use it as a library for the one function it defines

(import [beem [Hive Steem]])
(import [beem.account [Account]])
(import [beem.transactionbuilder [TransactionBuilder]])
(import [beem.discussions [Query Discussions]])
(import [beem.vote [ActiveVotes]])
(import vote)

(setv client (Hive))

(setv posts [])

(defn append-list [lis]
(.append posts lis))

(setv accounts ["shaka" "inber"]) ;; Put all the accounts you like in here no commas, since this is hy.
(for [a accounts]
(append-list ((. (Account a) get-blog) :limit 10)))

This gets the last 10 posts from each name in the list accounts then it takes those and puts it into the list posts. Which I can then use to get the relevant information out and send it to the function that will cast a vote for this post.

To get the relevant information from each post we need to retrieve the information, not very hard at all.

(import [beem [Hive Steem]])
(import [beem.account [Account]])
(import [beem.transactionbuilder [TransactionBuilder]])
(import [beem.discussions [Query Discussions]])
(import [beem.vote [ActiveVotes]])
(import vote)

(setv client (Hive))

(setv posts [])

(defn append-list [lis]
(.append posts lis))

(setv accounts ["shaka" "inber"]) ;; Put all the accounts you like in here no commas, since this is hy.
(for [a accounts]
(append-list ((. (Account a) get-blog) :limit 10)))

(setv to-vote [])
(defn append-other [item]
(.append to-vote item))

(for [post posts]
(for [p post]
(append-other (, (. p author) (. p permlink) 10))))

(return to-vote)

Now I only need to wire up the last thing, and it should do the voting for me.

Though I do need a little bit of code to check whether I even want to vote.

(if (> (.get-voting-power (Account "iobates")) 60)
    (for [item *to-vote*]
      (vote-for item))
    (.sleep time (* 60 60)))

The middle part is fairly simple, just a loop to go over the list and vote, only called when I have more power than 60. Just to make sure I maintain some value on my votes.

(for [item *to-vote*]
  (vote-for item))

Now it is simply a matter of wiring things up to work. You would probably want to change the names in the 'accounts' variable

(import [beem [Hive Steem]])
(import [beem.account [Account]])
(import [beem.transactionbuilder [TransactionBuilder]])
(import [beem.discussions [Query Discussions]])
(import [beem.vote [ActiveVotes]])
(import vote)

(setv client (Hive))

(setv posts [])

(defn append-list [lis]
(.append posts lis))

(setv accounts ["shaka" "inber"]) ;; Put all the accounts you like in here no commas, since this is hy.
(for [a accounts]
(append-list ((. (Account a) get-blog) :limit 10)))

(setv to-vote [])
(defn append-other [item]
(.append to-vote item))

(for [post posts]
(for [p post]
(append-other (, (. p author) (. p permlink) 10))))

(return to-vote)
(if (> (.get-voting-power (Account "iobates")) 60)
(for [item to-vote]
(vote-for item))
(.sleep time (* 60 60)))

Sort:  

I just posted an update on my voting script as well :) Is that lisp?

Kind of lisp, specifically a dialect built on top of python called hy, fully compatible with python.