This repository has been archived by the owner on Oct 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathbot.py
41 lines (35 loc) · 1.47 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This bot randomly upvotes posts
It upvotes a random post from the most recent [numPostsToConsider]
"""
import sys
import datetime
import os
import subprocess
from piston.steem import Steem
from random import randint
# grab config vars
percentChanceToPost = int(os.environ.get('percentChanceToPost'))
numPostsToConsider = int(os.environ.get('numPostsToConsider'))
voteWeight = int(os.environ.get('voteWeight'))
steemPostingKey = os.environ.get('steemPostingKey')
steemAccountName = os.environ.get('steemAccountName')
# [percentChanceToPost] chance to proceed past this block
i = randint(1, 100)
if i > percentChanceToPost:
print('[{:%Y-%m-%d, %H:%M:%S}] No action (failed random roll {}>{})\n'.format(datetime.datetime.now(), i, percentChanceToPost))
sys.exit(1)
# initialize steem object
steem = Steem(wif=steemPostingKey)
# use piston to set default voter and author
subprocess.call(['piston', 'set', 'default_voter', steemAccountName])
subprocess.call(['piston', 'set', 'default_author', steemAccountName])
# upvote random post from the most recent [numPostsToConsider]
posts = steem.get_posts(limit=numPostsToConsider, sort='created')
postId = randint(0, numPostsToConsider-1)
try:
steem.vote(posts[postId]["identifier"], voteWeight)
except:
print('[{:%Y-%m-%d, %H:%M:%S}] Vote failed: {}\n'.format(datetime.datetime.now(), sys.exc_info()[0]))
else:
print('[{:%Y-%m-%d, %H:%M:%S}] Vote succeeded: {}\n'.format(datetime.datetime.now(), posts[postId]["identifier"]))