Update for Steem Basic Income Automation - get_blog and comment_history replaced and comment upvoting enabled

in #utopian-io6 years ago (edited)

Repository

https://github.com/holgern/steembasicincome

Comment upvote enabled and sbi_update_post_count.py removed

The old solution with sbi_update_post_count.py was checking only one account at a time. This was to slow and the comment_upvote flag could not be set fast enough.

The comment_upvote flag is set when last_post is older than 7 days and comments willl be upvoted until a post is written.

last_post, last_comment and comment_upvote are now updated in sbi_store_member_hist.py by:

for op in b.stream(start=int(start_block), stop=int(end_block), opNames=["vote", "comment"], threading=False, thread_num=8):
        if op["type"] == "comment":
            if op["author"] not in member_accounts:
                continue
            try:
                c = Comment(op, steem_instance=stm)
                c.refresh()
            except:
                continue
            main_post = c.is_main_post() 
            if main_post:
                member_data[op["author"]]["last_post"] = c["created"]
            else:
                member_data[op["author"]]["last_comment"] = c["created"]
                
            if member_data[op["author"]]["last_post"] is None:
                member_data[op["author"]]["comment_upvote"] = 1
            elif addTzInfo(member_data[op["author"]]["last_post"]) < date_7_before:
                member_data[op["author"]]["comment_upvote"] = 1
            elif member_data[op["author"]]["comment_upvote"] == 1:
                member_data[op["author"]]["comment_upvote"] = 0
            member_data[op["author"]]["updated_at"] = c["created"]
            updated_member_data.append(member_data[op["author"]])

where b is a Blockchain object from beem.blockchain and date_7_before contains the datetime from 7 days before now.

get_blog and comment_history replaced

As the full-node api.steemit.com does not support get_blog anymore, I replaced it with fetching the account history operation itself. I created a new function get_newest to read only the newest account history operation from the database:

    def get_newest(self, op_types = [], limit=100):
        ops = []
        table = self.db[self.__tablename__]
        for op in table.find(order_by='-op_acc_index'):
            if op["type"] in op_types or len(op_types) == 0:
                ops.append(op)
            if len(ops) >= limit:
                return ops
        return ops

This function can be used to replace get_blog:

if account["name"] == "steembasicincome":
    ops = accountTrx["sbi"].get_newest(op_types=["comment"], limit=500)
else:
    ops = accountTrx[account["name"]].get_newest(op_types=["comment"], limit=500)
blog = []
for op in ops[::-1]:
    comment = (json.loads(op["op_dict"]))    
    if comment["parent_author"] == "" and comment["author"] == account["name"] and formatTimeString(comment["timestamp"]) > addTzInfo(last_paid_post):
        try:
            c = Comment(comment, steem_instance=stm)
            c.refresh()
            blog.append(c)
        except:
            continue

blog contains now the same posts that would be returned by get_blog. comment_history can be replaced with the same code, only

 if comment["parent_author"] == "" and comment["author"] == account["name"] and formatTimeString(comment["timestamp"]) > addTzInfo(last_paid_post):

is replaced by:

if comment["parent_author"] != "" and comment["author"] == account["name"] and formatTimeString(comment["timestamp"]) > addTzInfo(last_paid_comment):

posts with a nsfw or sbi-skip tag will be skipped

This is hard coded at the moment:

skip = False
for tag in c["tags"]:
    if tag.lower() in ["nsfw", "sbi-skip"]:
        skip = True

The post and comment database has now a new boolean field which is set byskip. Only posts are upvoted with skip == False

Commits

Replace get_blog and comment_history with already stored account history ops

  • commit 733f0fb
  • new function get_newest for receiving a limited number of account history ops from the database

skip posts with specific tags

  • commit 7f453f4
  • update sql structure
  • use accounts and other_accounts from database only
  • skip posts with specific tags
  • limit upvoted posts/comments to the last 24 hours

last_comment and last post is took directly from the scanned blocks

  • commit 655122b
  • sbi_update_post_count.py removed, last_comment and last_post is took directly from the scanned blocks in sbi_store_member_hist.py
  • sbi status comments improved, when comments from a member are upvoted
  • post will be also upvoted when the comment_upvote flag is set

Comment upvoting prepared

  • commit 1ab0bd1
  • 2x minimum_vote_threshold for comment upvoting
  • sbi status adapted for comment upvoting
  • bug fix for account history storage

GitHub Account

https://github.com/holgern

Sort:  

Thank you for your contribution.

  1. ["nsfw", "sbi-skip"] could be configured somewhere instead of being hard-coded in the code.
  2. Although must of your code is very clean and straightforward, I find literally no comments - a few comments would be nice.
  3. dead code such as if False: should be removed. also you have commented out code.
  4. constants event it is fixed-account name such as steembasicincome should be defined as a constant.

Happy new year!

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @justyy! Keep up the good work!

Your code updates do better than my status updates!

Posted using Partiko Android

These updates are awesome, I got surprised by sbi votes on my comments xD

Posted using Partiko Android

I still do not understand very well what it consists ... But we will see my respects.

Thank you so much for participating the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 7.282 which ranks you at #65 across all Steem accounts.
Your rank has improved 1 places in the last three days (old rank 66).

In our last Algorithmic Curation Round, consisting of 209 contributions, your post is ranked at #3. Congratulations!

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

This post has been included in today's SOS Daily News - a digest of all you need to know about the State of Steem.



Hey, @holger80!

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

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

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

Vote for Utopian Witness!