votebot 0.0.6

in #steemit6 years ago (edited)

Hi,
below you'll find source code for my 'voting proxy' and instructions on how to run it ...

import time
import argparse

from sys import stdout
from datetime import datetime

from steem import Steem

parser = argparse.ArgumentParser()
parser.add_argument('--user', action='store')
parser.add_argument('--pk', action='store')

version = '0.0.6'

args = parser.parse_args()

apiConn = Steem(keys=[args.pk])
apiUser = args.user

votePower = 11 # SET YOUR VOTING POWER

voteDelay = 30

startBlock = apiConn.head_block_number - (voteDelay * 20)

currentBlock = startBlock

toi = ['vote']

curatorsArray = ['ned','blocktrades','dantheman']     # LIST OF CURATORS YOU WANT TO FOLLOW
authorsArray = ['steemsports','gavvet','knozaki2015'] # LIST OF AUTHORS YOU WANT TO FOLLOW

class colors:
    WIPE = '\033[0m'
    ERRR = '\033[91m'
    GOOD = '\033[92m'
    IGNR = '\033[93m'
    EXIT = '\033[94m'
    LOGO = '\033[90m'
    USER = '\033[97m'

def write(input):

    stdout.write(input)
    stdout.flush()

def update():

    global apiConn
    global apiUser
    global votePower
    global currentBlock

    global toi
    global curatorsArray
    global authorsArray

    while True:

        try:

            query = apiConn.get_block(currentBlock)

            queryTime = datetime.strptime(str(query['timestamp']), '%Y-%m-%dT%H:%M:%S')

            queryTransactions = query['transactions']
            queryLength = len(queryTransactions)

            write('{ ')

            for i in range(0, queryLength):

                for j in range(0, len(queryTransactions[i]['operations'])):

                    operation = queryTransactions[i]['operations'][j]
                    type = operation[0]

                    if type in toi:

                        author = operation[1]['author']
                        voter = operation[1]['voter']
                        weight = operation[1]['weight']

                        if weight > 0 and apiUser != author:

                            if author in authorsArray or voter in curatorsArray:

                                write('[%s+%s]' % (colors.GOOD, colors.WIPE))

                                try:

                                    votes = apiConn.get_active_votes(operation[1]['author'], operation[1]['permlink'])

                                    voters = []

                                    for v in votes:

                                        voters.append(v['voter'])

                                    if apiUser not in voters:

                                        try:

                                            apiConn.vote('@%s/%s' % (operation[1]['author'], operation[1]['permlink']), votePower, apiUser)
                                            write('[%sVOTING%s]' % (colors.GOOD, colors.WIPE))
                                            time.sleep(5)

                                        except Exception as e:

                                            write('[%sERROR%s: %s]' % (colors.ERRR, colors.WIPE,e))

                                    else:

                                        write('[%sALREADY VOTED%s]' % (colors.IGNR, colors.WIPE))

                                except Exception as e:

                                    write('[%sERROR%s: %s]' % (colors.ERRR, colors.WIPE,e))
                            else:

                                write('[%s+%s]' % (colors.IGNR, colors.WIPE))

                        else:

                            write('[%s-%s]' % (colors.ERRR, colors.WIPE))

                    else:

                        write('[ ]')

            currentBlock = currentBlock + 1
            write(' }')
            time.sleep(3)

        except KeyboardInterrupt as e:

            write('\n[%sEXIT%s]\n' % (colors.EXIT, colors.WIPE))
            break

        except Exception as e:

            write('[%sERROR%s: %s]' % (colors.ERRR, colors.WIPE,e))

write('[ %sV O T E B O T%s v%s ] [ %s@%s%s ]\n\n' % (colors.LOGO, colors.WIPE, version, colors.USER, apiUser, colors.WIPE))

update()

INSTRUCTIONS (LINUX):

  1. Install steem libs:pip3 install --user --upgrade steem
  2. Change votePower, curratorsArray, authorsArrayin the source code to your liking.
  3. Run the bot on screen:screen -S <SCREEN_NAME> python3 <SCRIPT_NAME> --user <USER_NAME> --pk <PRIVATE_POSTING_KEY>
  4. CTRL + A + D and enjoy ;D
Sort:  

Good information
Thank

Congratulations @murh! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63126.02
ETH 2553.49
USDT 1.00
SBD 2.78