Skip to content

Commit

Permalink
Add support for minimum_post_age and maximum_post_rewards value. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emre committed Apr 4, 2018
1 parent f23df17 commit f8066cb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Configuration is stored in JSON files. You can find an example in the repository
|:-------------------:|------------------------------------------------------|
| NODES | A list of steem nodes to connect |
| BOT_ACCOUNT | Bot account to vote |
| TAGS | Target tags to upvote posts |
| TAGS | Target tags to upvote posts |
| MINIMUM_VP_TO_START | Bot should sleep until this VP is generated |
| VOTE_WEIGHT | Vote weight for every upvote (in percent) |
| VOTE_COUNT | How many votes should be casted in each voting round |
Expand All @@ -38,3 +38,5 @@ Configuration is stored in JSON files. You can find an example in the repository
| TAG_BLACKLIST | A list of authors to ignore |
| MINIMUM_WORD_COUNT | Minimum Word Count |
| APP_WHITELIST | Only vote posts posted from a specified platform |
| MINIMUM_POST_AGE | Minimum post age in hours |
| MAXIMUM_POST_REWARDS| Skip posts earned more than $N rewards |
56 changes: 53 additions & 3 deletions tagbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dateutil.parser import parse
from steem.account import Account
from steem.post import Post
from steem.amount import Amount

from tagbot.utils import get_steem_conn, get_current_vp, url, reputation, tokenize

Expand Down Expand Up @@ -58,12 +59,61 @@ def reputation_is_enough(self, author_rep):
# if the user rep is below than 25, than discard the post.
return reputation(author_rep) > self.config["MINIMUM_AUTHOR_REP"]

def fetch_tag(self, tag, start_author=None, start_permlink=None, posts=None, scanned_pages=None):

logger.info("Fetching tag: #%s", tag)

if not scanned_pages:
scanned_pages = 0

if not posts:
posts = []

query = {
"limit": 100,
"tag": tag,
}
if start_author:
query.update({
"start_author": start_author,
"start_permlink": start_permlink,
})
post_list = list(self.steemd_instance.get_discussions_by_created(query))
for post in post_list:
created_at = parse(post["created"])

if (datetime.utcnow() - created_at).days > 5:
return posts

elapsed_hours = (datetime.utcnow() - created_at).total_seconds() // 3600
if self.config.get("MINIMUM_POST_AGE"):
if self.config.get("MINIMUM_POST_AGE") > elapsed_hours:
continue

if self.config.get("MAXIMUM_POST_REWARDS"):
pending_payout = Amount(post.get("pending_payout_value"))
if pending_payout.amount > self.config.get("MAXIMUM_POST_REWARDS"):
print(post)
continue

posts.append(post)

if scanned_pages > 300 or len(posts) > 100:
logger.info("%s posts found at #%s tag.", len(posts), tag)
return posts

return self.fetch_tag(
tag,
start_author=post["author"],
start_permlink=post["permlink"],
posts=posts,
scanned_pages=scanned_pages + 1,
)

def start_voting_round(self):
posts = []
for tag in self.target_tags:
logger.info("Fetching #%s tag", tag)
query = {"limit": 100, "tag": tag}
posts += list(self.steemd_instance.get_discussions_by_created(query))
posts += self.fetch_tag(tag)
logger.info("%s posts found.", len(posts))

already_voted = self.last_voted_accounts()
Expand Down

0 comments on commit f8066cb

Please sign in to comment.