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
def in_recent_n_days(post, n, reblog=False): key = "reblogged" if reblog else "created" if isinstance(post[key], str): created = datetime.strptime( post[key], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=pytz.UTC) else: created = post[key] return in_recent_days(created, n)
def in_recent_n_days(post, n): return in_recent_days(post['created'], n)
def _is_recent(self, account, days): return in_recent_days(account.birthday(), days)
def is_recent(self, post, days): return in_recent_days(post['created'], days)