def curation_stats(self): trailing_24hr_t = time.time() - datetime.timedelta( hours=24).total_seconds() trailing_7d_t = time.time() - datetime.timedelta( days=7).total_seconds() reward_24h = 0.0 reward_7d = 0.0 for reward in take(5000, self.history_reverse(filter_by="curation_reward")): timestamp = parse_time(reward['timestamp']).timestamp() if timestamp > trailing_7d_t: reward_7d += Amount(reward['reward']).amount if timestamp > trailing_24hr_t: reward_24h += Amount(reward['reward']).amount reward_7d = self.converter.vests_to_sp(reward_7d) reward_24h = self.converter.vests_to_sp(reward_24h) return { "24hr": reward_24h, "7d": reward_7d, "avg": reward_7d / 7, }
def take(self, limit=5): """ Take up to n (n = limit) posts/comments at a time. You can call this method as many times as you want. Once there are no more posts to take, it will return []. Returns: List of posts/comments in a batch of size up to `limit`. """ # get main posts only comment_filter = is_comment if self.comments_only else complement( is_comment) hist = filter(comment_filter, self.history) # filter out reblogs def match_author(x): return x['author'] == self.account.name hist2 = filter(match_author, hist) # post edits will re-appear in history # we should therefore filter out already seen posts def ensure_unique(post): if post['permlink'] not in self.seen_items: self.seen_items.add(post['permlink']) return True unique = filter(ensure_unique, hist2) serialized = filter(bool, map(silent(Post), unique)) batch = take(limit, serialized) return batch
def update_account_ops_quick(mongo, username, batch_size=200, steemd_instance=None): """ Only update the latest missing history, limited to 1 batch of defined batch_size. """ start_index = account_operations_index(mongo, username) # fetch latest records and update the db history = Account( username, steemd_instance=steemd_instance).history_reverse(batch_size=batch_size) for event in take(batch_size, history): if event['index'] < start_index: return with suppress(DuplicateKeyError): mongo.AccountOperations.insert_one(json_expand(typify(event)))