Basis for a comment upvote bot

Sorry, I have been out for a while, and this one isn't bee themed as I am really digging the Borg theme at the moment. But I present to you:

A comment upvote bot

This bot was created because my simple monitor bot seemed to be the most popular article so far. Source can be found at GitHub If you have other things you would like me to attempt please, ask away!

#!/usr/bin/env python3

import os
import re

from beem import Hive
from beem.account import Account
from beem.blockchain import Blockchain
from beem.comment import Comment
from beem.instance import set_shared_blockchain_instance
from beem.utils import construct_authorperm

posting_key = os.environ["BOT"]
REGEX = '(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9]+)'
botname = "thecrazygm"
weight = 100

hive = Hive(node=['https://api.hive.blog'], keys=posting_key)
set_shared_blockchain_instance(hive)
chain = Blockchain()
followees = Account(botname).get_following()


def summon_upvotebot():
    print(f'[Starting up]')
    while True:
        try:
            for post in chain.stream(opNames="comment", threading=True, thread_num=5):
                mentions = re.findall(REGEX, post["body"])
                comment = Comment(post)
                perm = comment.authorperm
                parent = construct_authorperm(
                    Comment(perm).parent_author, Comment(perm).parent_permlink)
                author = post['author']
                if Comment(perm).is_comment:
                    if botname in mentions:
                        print(
                            f'[{author} just mentioned {botname} in {perm} in reply to {parent}]')
                        if author in followees:
                            Comment(parent).upvote(
                                weight=weight, voter=botname)
                            print(
                                f'[{botname} voted {weight}% on {parent} per {author}\'s request]')
                        else:
                            print(
                                f'[{author} tried to summon {botname} but is not in the whitelist]')
        except Exception as error:
            print(repr(error))
            continue


if __name__ == '__main__':
    summon_upvotebot()

Now this takes in consideration that you have an env variable called BOT set to your posting key e.g. export BOT=mypostingkeygoeshere from the Linux/Mac cli (not even sure how this is done in Windows, someone care to share?)

This is a comment bot, looking for your bot name in a comment to upvote the parent comment and only if that person is in the bot's following list. This was done for two reasons:

  1. to create a simple 'whitelist'
  2. to show some of the other ways you can use a monitor bot for neat things

Normally we see another comment saying (this has been upvoted by blahblah, but I feel that is spam)

Until next time,
Michael Garcia a.k.a. @TheCrazyGM
p.s. I'm still feeling quite sick as why this is so brief and doesn't walk through the code with explanations.

H2
H3
H4
3 columns
2 columns
1 column
9 Comments