Steemautomated: 0.0.4 - Trailing Has Been Enabled + Several Minor Upgrades

in utopian-io •  3 months ago

Screenshot 2018-07-24 18.50.48.png

Repository

https://github.com/Juless89/steemautomated

Commit request

https://github.com/Juless89/steemautomated/commit/fb89c1b7eb8444cfe48f0cd54d3cc60f777f95be

Website

https://steemautomated.eu/

New Features

Trailing is now live

In addition to setting up custom voting rules it is now possible to set up custom trailing rules as well.

Every block a unique list of accounts that are being trailed are fetched from the server. They are filtered in case the user has not entered the name correctly.

# Fetch trails to be tracked
self.trail_list = []
for trail in self.db.get_trails():
    trail = re.sub(
        '[^A-Za-z0-9^-]+', '',
        trail[0].lower(),
    )
    self.trail_list.append(trail)



Then in addition to listening on comments, votes have been added to be processed.

elif transaction_type == 'vote':
    vote = transaction['operations'][0][1]
    self.process_vote(vote)



The vote data is extracted and compared to the trail_list. In case of a hit it will be prepared to be added to the queue.

# Votes are checked for their voter and if the voter is being trailed
def process_vote(self, vote):
    trail = vote['voter']
     if trail in self.trail_list:
        author = vote['author']
        permlink = vote['permlink']
        weight = vote['weight']
        print(f"\n\nTrail: {trail}\nAuthor: {author}\nPermlink: " +
              f"{permlink}\nWeight: {weight}\n")
         self.add_trail_to_queue(trail, author, permlink, weight)



For the specific trail account a list is fetched from the database with all the accounts that are trailing this account. Then vote rules are created based on their parameters. Since the weight is relative to the weight of the vote from the trail account. The weight for the voter's account is calculated based on the weight from the trail account. After this the vote rule is added to the queue and handled like a normal vote rule. There is 1 addition, type has been added to the queue table structure to distinguish trail and normal votes. As they both have their own log.

# Trails with a delay of 0 are immediatly voted upon. Else the expire_on
 # time of the vote is calculated and added to the queue. The weight of
 # vote is relative between the weight of the vote casted by the voter that
 # is being trailed and the trailer who has set a custom relative weight.
 def add_trail_to_queue(self, trail, author, permlink, weight):
     for voter in self.db.get_trail_voters(trail):
         voter, voter_weight, limit, delay = voter
         vote_log = self.db.get_trail_log(voter, trail, self.timestamp)
         upvote_weight = weight/100 * voter_weight/100
         print(f"\nTrail: {trail}\nVoter: {voter}\nAuthor: {author}\n" +
               f"Weight: {upvote_weight}\nLimit: {limit}\nDelay: {delay}\n")
          if delay != 0:
             self.db.add_trail_to_queue(
                 trail, author, voter, upvote_weight, limit, delay,
                 permlink, self.timestamp,
             )
         elif len(vote_log) < limit:
             self.db.add_to_trail_log(
                 author, voter, permlink,
                 upvote_weight, self.timestamp,
             )
             self.vote(voter, author, permlink, weight, type)

New trailing page

The trailing page has been updated to reflect the changes.
Screenshot 2018-08-01 09.50.16.png

Check if post is already voted on

In addition some small changes were made to improve the error rate. Before the vote is to take place the post is looked up to see if the voter has already voted in a similar way.

# Go thourgh all the active votes and look if the voter has already
# voted on this post.
def is_already_voted(self, voter, author, permlink):
    try:
        identifier = f"@{author}/{permlink}"
        post = Post(identifier, self.steem)
        active_votes = post['active_votes']
        for vote in active_votes:
            if vote['voter'] == voter:
                return 1
        return 0
    except Exception as error:
        return 0



Further also as advised by @justyy

  • the mysql and client access details are now defined outside of the constructer.
  • verify_post has been renamed to is_new_post

Still in progress:

There are some broad execeptions, which is in general a bad practice.

GitHub Account

https://github.com/Juless89

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...

Excellent

Hey @steempytutorials
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @steempytutorials! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

Award for the total payout received

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @steempytutorials! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @steempytutorials! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemitBoard Ranking update - Steem Power, Followers and Following added

Support SteemitBoard's project! Vote for its witness and get one more award!