async def get_following(account: str, start: str, follow_type: str, limit: int): """Get all accounts `account` follows. (EOL)""" following = cursor.get_following( valid_account(account), valid_account(start or '', allow_empty=True), _follow_type_to_int(follow_type), valid_limit(limit, 1000)) return [_legacy_follower(account, name, follow_type) for name in following]
def _get_blog(account: str, start_index: int, limit: int = None): """Get posts for an author's blog (w/ reblogs), paged by index/limit. Examples: (acct, 2) = returns blog entries 0 up to 2 (3 oldest) (acct, 0) = returns all blog entries (limit 0 means return all?) (acct, 2, 1) = returns 1 post starting at idx 2 (acct, 2, 3) = returns 3 posts: idxs (2,1,0) """ if not limit: limit = start_index + 1 ids = cursor.pids_by_blog_by_index(valid_account(account), valid_offset(start_index), valid_limit(limit, 500)) out = [] idx = int(start_index) for post in load_posts(ids): reblog = post['author'] != account reblog_on = post['created'] if reblog else "1970-01-01T00" out.append({ "blog": account, "entry_id": idx, "comment": post, "reblog_on": reblog_on }) idx -= 1 return out
async def get_replies_by_last_update(start_author: str, start_permlink: str = '', limit: int = 20, truncate_body: int = 0): """Get all replies made to any of author's posts.""" ids = cursor.pids_by_replies_to_account( valid_account(start_author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 50)) return load_posts(ids, truncate_body=truncate_body)
async def get_discussions_by_comments(start_author: str, start_permlink: str = '', limit: int = 20, truncate_body: int = 0): """Get comments by made by author.""" ids = cursor.pids_by_account_comments( valid_account(start_author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 20)) return load_posts(ids, truncate_body=truncate_body)
async def get_followers(account: str, start: str, follow_type: str, limit: int): """Get all accounts following `account`. (EOL)""" assert follow_type != 'ignore', 'no index for ignored-by' followers = cursor.get_followers( valid_account(account), valid_account(start or '', allow_empty=True), _follow_type_to_int(follow_type), valid_limit(limit, 1000)) return [_legacy_follower(name, account, follow_type) for name in followers]
async def get_discussions_by_blog(tag: str, start_author: str = '', start_permlink: str = '', limit: int = 20, truncate_body: int = 0): """Retrieve account's blog posts.""" ids = cursor.pids_by_blog( valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 20)) return load_posts(ids, truncate_body=truncate_body)
async def get_discussions_by_comments(context, start_author=None, start_permlink='', limit=20): """Get comments by made by author.""" assert start_author, '`start_author` cannot be blank' ids = await cursor.pids_by_account_comments( context['db'], valid_account(start_author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts(context['db'], ids)
async def get_replies_by_last_update(context, start_author=None, start_permlink='', limit=20): """Get all replies made to any of author's posts.""" assert start_author, '`start_author` cannot be blank' ids = await cursor.pids_by_replies_to_account( context['db'], valid_account(start_author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts(context['db'], ids)
async def get_account_reputations(context, account_lower_bound: str = None, limit: int = None): """List account reputations""" return { 'reputations': await cursor.get_account_reputations(context['db'], account_lower_bound, valid_limit(limit, 1000)) }
async def get_discussions_by_feed(context, tag=None, start_author='', start_permlink='', limit=20): """Retrieve account's personalized feed.""" assert tag, '`tag` cannot be blank' res = await cursor.pids_by_feed_with_reblog( context['db'], valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts_reblogs(context['db'], res)
async def get_discussions_by_blog(context, tag=None, start_author='', start_permlink='', limit=20): """Retrieve account's blog posts, including reblogs.""" assert tag, '`tag` cannot be blank' ids = await cursor.pids_by_blog( context['db'], valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts(context['db'], ids)
async def get_discussions_by_created(context, start_author='', start_permlink='', limit=20, tag=None): """Query posts, sorted by creation date.""" ids = await cursor.pids_by_query( context['db'], 'created', valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100), valid_tag(tag, allow_empty=True)) return await load_posts(context['db'], ids)
async def get_discussions_by_created(start_author: str = '', start_permlink: str = '', limit: int = 20, tag: str = None, truncate_body: int = 0): """Query posts, sorted by creation date.""" ids = cursor.pids_by_query( 'created', valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100), valid_tag(tag, allow_empty=True)) return load_posts(ids, truncate_body=truncate_body)
async def get_discussions_by_feed(tag: str, start_author: str = '', start_permlink: str = '', limit: int = 20, truncate_body: int = 0): """Retrieve account's personalized feed.""" res = cursor.pids_by_feed_with_reblog( valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return load_posts_reblogs(res, truncate_body=truncate_body)
async def get_post_discussions_by_payout(context, start_author: str = '', start_permlink: str = '', limit: int = 20, tag: str = None, truncate_body: int = 0): """Query top-level posts, sorted by payout.""" ids = await cursor.pids_by_query( context['db'], 'payout', valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100), valid_tag(tag, allow_empty=True)) return await load_posts(context['db'], ids, truncate_body=truncate_body)
async def get_discussions_by_comments(context, start_author: str = None, start_permlink: str = '', limit: int = 20, truncate_body: int = 0, filter_tags: list = None): """Get comments by made by author.""" assert start_author, '`start_author` cannot be blank' assert not filter_tags, 'filter_tags not supported' ids = await cursor.pids_by_account_comments( context['db'], valid_account(start_author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts(context['db'], ids, truncate_body=truncate_body)
async def get_discussions_by_hot(context, start_author: str = '', start_permlink: str = '', limit: int = 20, tag: str = None, truncate_body: int = 0, filter_tags: list = None): """Query posts, sorted by hot score.""" assert not filter_tags, 'filter_tags not supported' ids = await cursor.pids_by_query( context['db'], 'hot', valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100), valid_tag(tag, allow_empty=True)) return await load_posts(context['db'], ids, truncate_body=truncate_body)
async def get_discussions_by_blog(context, tag: str = None, start_author: str = '', start_permlink: str = '', limit: int = 20, truncate_body: int = 0, filter_tags: list = None): """Retrieve account's blog posts, including reblogs.""" assert tag, '`tag` cannot be blank' assert not filter_tags, 'filter_tags not supported' ids = await cursor.pids_by_blog( context['db'], valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return await load_posts(context['db'], ids, truncate_body=truncate_body)
async def get_discussions_by_author_before_date(author: str, start_permlink: str = '', before_date: str = '', limit: int = 10): """Retrieve account's blog posts, without reblogs. NOTE: before_date is completely ignored, and it appears to be broken and/or completely ignored in steemd as well. This call is similar to get_discussions_by_blog but does NOT serve reblogs. """ # pylint: disable=invalid-name,unused-argument ids = cursor.pids_by_blog_without_reblog( valid_account(author), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 100)) return load_posts(ids)
async def get_following(context, account: str, start: str, follow_type: str = None, limit: int = None, **kwargs): """Get all accounts `account` follows. (EOL)""" # `type` reserved word workaround if not follow_type and 'type' in kwargs: follow_type = kwargs['type'] if not follow_type: follow_type = 'blog' following = await cursor.get_following( context['db'], valid_account(account), valid_account(start, allow_empty=True), valid_follow_type(follow_type), valid_limit(limit, 1000)) return [_legacy_follower(account, name, follow_type) for name in following]
async def get_trending_tags(context, start_tag: str = '', limit: int = 250): """Get top 250 trending tags among pending posts, with stats.""" limit = valid_limit(limit, ubound=250) start_tag = valid_tag(start_tag or '', allow_empty=True) if start_tag: seek = """ HAVING SUM(payout) <= ( SELECT SUM(payout) FROM hive_posts_cache WHERE is_paidout = '0' AND category = :start_tag) """ else: seek = '' sql = """ SELECT category, COUNT(*) AS total_posts, SUM(CASE WHEN depth = 0 THEN 1 ELSE 0 END) AS top_posts, SUM(payout) AS total_payouts FROM hive_posts_cache WHERE is_paidout = '0' GROUP BY category %s ORDER BY SUM(payout) DESC LIMIT :limit """ % seek out = [] for row in await context['db'].query_all(sql, limit=limit, start_tag=start_tag): out.append({ 'name': row['category'], 'comments': row['total_posts'] - row['top_posts'], 'top_posts': row['top_posts'], 'total_payouts': "%.3f SBD" % row['total_payouts'] }) return out
async def get_discussions_by_feed(tag: str, start_author: str = '', start_permlink: str = '', limit: int = 20, truncate_body: int = 0): """Retrieve account's personalized feed.""" res = cursor.pids_by_feed_with_reblog( valid_account(tag), valid_account(start_author, allow_empty=True), valid_permlink(start_permlink, allow_empty=True), valid_limit(limit, 20)) reblogged_by = dict(res) posts = load_posts([r[0] for r in res], truncate_body=truncate_body) # Merge reblogged_by data into result set for post in posts: rby = set(reblogged_by[post['post_id']].split(',')) rby.discard(post['author']) if rby: post['reblogged_by'] = list(rby) return posts
def __used_refs(): # pylint valid_limit('')