Repository
https://github.com/Juless89/steemautomated
Commit request
https://github.com/Juless89/steemautomated/commit/8f6e256a7b9688252941767772cb6746ccd0e4e1
Website
New Features
Voting is now live
I created a server side version of the standalone voter that uses a MySQL database and Steemconnect authentication. The flow for a vote is as follows:
Every block a list of authors to be upvoted is fetched from the server.
# Fetch author to be upvoted list
self.upvote_list = []
for author in self.db.get_authors():
self.upvote_list.append(author[0])
The blocks transactions are scanned for comment which are then processed
for transaction in block['transactions']:
if transaction['operations'][0][0] == 'comment':
comment = transaction['operations'][0][1]
self.process_comment(comment)
The comment is verified to be a new post and the author is verified to be in the upvote list. If so post is send to the queue.
def process_comment(self, comment):
parent_author = comment['parent_author']
author = comment['author']
if parent_author == '' and author in self.upvote_list:
permlink = comment['permlink']
if self.verify_post(author, permlink):
print(f'\n\n{self.timestamp} Block: {self.block}')
print(f"New post\nAuthor: {author}")
self.add_to_queue(author, permlink)
For each author all voting rules are retrieved and checked for their specific rules. If the daily limit has not been reached than the post can be added to the queue. When the delay is 0 a direct vote is casted. Posts are added to both the queue and the log. The log is used to determine the daily posts an author has already made. As it is possible to make a new post while there is already a post in the queue. In this instance just checking the log would retrieve an incorrent number.
def add_to_queue(self, author, permlink):
for vote in self.db.get_votes(author):
voter, weight, limit, delay = vote
vote_log = self.db.get_vote_log(voter, author, self.timestamp)
print(f"\nVoter: {voter}\nWeight: {weight}\nLimit: " +
f"{limit}\nDelay: {delay}")
if delay != 0:
self.db.add_to_queue(
author, voter, weight, limit, delay,
permlink, self.timestamp,
)
elif len(vote_log) < limit:
self.db.add_to_log(
author, voter, permlink,
weight, self.times,
)
self.vote(voter, author, permlink, weight)
To perform a vote first the access token is checked to still be valid, if not is is updated. The vote is then broadcasted. In case of any errors the post gets added to the error_log for manual review. As of now it does not check yet for revoked authorisation on the Steemconnect side. A user has revoked access, his rules will result in an error message. Success or fail, the vote is removed from the queue and has its log updated.
def vote(self, voter, author, permlink, weight):
result = self.db.get_user_auth(voter)
access_token, refresh_token, expire_on = result[0]
dt = datetime.now()
c = Client(
client_id="",
client_secret="",
access_token=access_token,
)
try:
# Verify access_token
if dt > expire_on:
access_token = self.refresh_token(refresh_token)
result = c.refresh_access_token(
refresh_token,
"login,vote" # scopes
)
access_token = result['access_token']
refresh_token = result['refresh_token']
expires_in = result['expires_in']
self.db.update_authentication_tokens(
voter,
access_token,
refresh_token,
expires_in,
self.timestamp,
)
print('Updated access token\n')
# Perform vote
vote = Vote(voter, author, permlink, weight)
result = c.broadcast([vote.to_operation_structure()])
# Log vote
if 'error' in result:
message = result['error_description']
self.db.add_to_error_log(
voter, author, permlink, weight,
message, self.timestamp,
)
else:
message = 'Succes'
self.db.update_log(voter, permlink, message)
print(f"Voter: {voter}\nAuthor: {author}\n" +
f"Permlink: {permlink}\nWeight: {weight}\n" +
"Upvote succes\n")
except Exception as error:
self.db.add_to_error_log(
voter, author, permlink,
weight, error, self.timestamp,
)
Latest votes
In addition the front page now offers a live overview of the latest votes.