def vote(self, post=None, url=None, weight=None, retries=VOTE_RETRIES): c = SteemComment(comment=post, url=url) if retries <= 0: logger.error("Vote {} failed after retries for {} times".format( c.get_url(), VOTE_RETRIES)) return False while time.time() - self.last_vote_timestamp < MINIMUM_VOTE_INTERVAL: wait_time = round( MINIMUM_VOTE_INTERVAL + random.random() * MINIMUM_VOTE_INTERVAL * 0.2, 2) logger.info( "Sleep {} seconds to avoid voting too frequently.".format( wait_time)) time.sleep(wait_time) if time.time() - self.last_vote_timestamp >= MINIMUM_VOTE_INTERVAL: return self.vote(post, url, weight, retries - 1) success = False try: weight = weight or self.weight(c) success = self.voter.vote(c.get_comment(), weight=weight) self.last_vote_timestamp = time.time() except: logger.error( "Failed when voting {} with error: {} . {} retry times left.". format(c.get_url(), traceback.format_exc(), retries - 1)) return self.vote(post, url, weight, retries - 1) self.after_success(success) return success
def vote(self, post=None, url=None, weight=None, retries=VOTE_RETRIES): c = SteemComment(comment=post, url=url) if retries <= 0: logger.error("Vote {} failed after retries for {} times".format( c.get_url(), VOTE_RETRIES)) return False while time.time() - self.last_vote_timestamp < MINIMUM_VOTE_INTERVAL: self.sleep() if time.time() - self.last_vote_timestamp >= MINIMUM_VOTE_INTERVAL: return self.vote(post, url, weight, retries - 1) success = False try: weight = weight or self.weight(c) success = self.voter.vote(c.get_comment(), weight=weight) self.last_vote_timestamp = time.time() except: logger.error( "Failed when voting {} with error: {} . {} retry times left.". format(c.get_url(), traceback.format_exc(), retries - 1)) return self.vote(post, url, weight, retries - 1) self.after_success(success, c) return success
def _downvote(self, post, weight): c = SteemComment(comment=post) if not c.is_downvoted_by(self.author): post.downvote(weight=weight, voter=self.author) logger.info( "Downvoted to [{}] [{}] with weight [{:.2f}] successfully". format(post.title, c.get_url(), weight)) return True else: logger.info( "Skip downvote because I already downvoted this post [{}] [{}]" .format(post.title, c.get_url())) return False
def _write_content(self, post): folder = self._get_content_folder() c = SteemComment(comment=post) # retrieve necessary data from steem title = self._yaml_compatible(post.title, "''") # permlink = post["permlink"] permlink = self.permalink_filtering(post.title) body = c.get_compatible_markdown() position = self._get_position(body) date_str = post.json()["created"] date = date_str.replace('T', ' ') tags = "\n".join(["- {}".format(tag) for tag in c.get_tags()]) category = "\n".join(["- {}".format(c) for c in c.get_category()]) thumbnail = self._yaml_compatible(c.get_pic_url(), "") url = c.get_url() # build content with template template = get_message("blog", footer=True) content = template.format(title=title, permlink=permlink, position=position, date=date, tags=tags, category=category, thumbnail=thumbnail, body=body, url=url) # write into MD files filename = os.path.join(folder, "{}_{}.md".format(date_str.split('T')[0], permlink)) with open(filename, "w", encoding="utf-8") as f: f.write(content) logger.info("Download post [{}] into file {}".format(title, filename))
def what_to_vote(self, ops): # posted_with_steemcn = self.ops.is_app(APP) and not self.ops.is_comment() is_post = not self.ops.is_comment() if is_post: logger.info("Find post {} published with [{}] app".format( self.ops.get_url(), APP)) c = SteemComment(ops=ops) if c.is_upvoted_by(self.by()): logger.info("Post {} is already upvoted. Skip.".format( c.get_url())) return False else: return True return False
def what_to_vote(self, ops): posted_with_steemcn = self.ops.is_app( APP) and not self.ops.is_comment() if posted_with_steemcn: logger.info("Find post {} published with [{}] app".format( self.ops.get_url(), APP)) c = SteemComment(ops=ops) beneficiary = c.get_beneficiaries(account=BENEFICIARY_ACCOUNT) if beneficiary >= BENEFICIARY_THRESHOLD: logger.info("Post {} has set {} beneficiary.".format( self.ops.get_url(), beneficiary)) if c.is_upvoted_by(self.by()): logger.info("Post {} is already upvoted. Skip.".format( c.get_url())) return False else: return True return False