Example #1
0
    def read_posts(self):
        posts = {}
        votes = self.get_votes(self.account, up=self.upvote)
        for v in votes:
            # filter votes with 7 days
            # dt = datetime.strptime(v['time'], "%Y-%m-%dT%H:%M:%S")
            dt = datetime.strptime(v['last_update'], "%Y-%m-%dT%H:%M:%S")
            dt = dt.replace(tzinfo=timezone.utc)
            if not in_recent_days(dt, self.days):
                continue

            # get post data
            # authorperm = v['authorperm']
            authorperm = "@{}/{}".format(v['author'], v['permlink'])
            if not authorperm in posts:
                c = SteemComment(author_perm=authorperm)
                if not self.within_nth_day(c, self.days):
                    continue
                posts[authorperm] = {
                    "author": c.get_comment().author,
                    "permlink": v['permlink'],
                    "authorperm": authorperm,
                    "voters": [],
                    "percents": [],
                    "created": c.get_comment()['created']
                }
            # get voters and percentage
            posts[authorperm]['voters'].append(v['voter'])
            # posts[authorperm]['percents'].append(v['percent'])
            posts[authorperm]['percents'].append(v['vote_percent'])
        res = list(posts.values())
        res.sort(key=lambda post: post['created'])
        return res
Example #2
0
 def reply(self, message_id=None, post=None, url=None):
     """ reply to the' post """
     c = SteemComment(comment=post, url=url)
     receiver = c.get_comment().author
     if not self._has_replied(receiver, message_id):
         title = c.get_comment().title
         message = self._get_reply_body(message_id, receiver)
         self.writer.reply(c.get_comment(), message)
         self._add_reply_record(receiver, message_id, c)
         logger.info("Replied to @{}'s post [{}] with [{}] message".format(receiver, title, message_id))
         return True
     else:
         logger.info("Skip reply account @{} with [{}] message, because we already reliped before".format(receiver, message_id))
         return False
Example #3
0
    def vote(self, post=None, url=None):
        c = SteemComment(comment=post, url=url)
        receiver = c.get_comment().author
        title = c.get_comment().title

        if not c.is_upvoted_by(self.author):
            self.voter.upvote(c.get_comment(), weight=float(VOTE_WEIGHT))
            logger.info("I have upvoted @{}'s post [{}] successfully".format(
                receiver, title))
            return True
        else:
            logger.info(
                "Skip upvote @{} because I already upvoted his/her post [{}]".
                format(receiver, title))
            return False
Example #4
0
    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
Example #5
0
    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
Example #6
0
 def perform_vote():
     if isinstance(ops, Comment):
         c = SteemComment(comment=ops)
     else:
         c = SteemComment(ops=ops)
     self.append_to_vote_queue(post=c.get_comment())
Example #7
0
 def print_post(ops):
     c = SteemComment(ops=ops)
     if not c.get_comment().is_comment():
         c.log()