steem-python for dummies #12 - Lookups (Discussion Queries)
Hello,
This is the 12. post of "steem-python for dummies" series. If you didn't read the older ones take your time and have a look.
- steem-python for dummies #1 - Introduction and Basic Operations
- steem-python for dummies #2 - Playing with account data
- steem-python for dummies #3 - Coding an upvote bot
- steem-python for dummies #4 - Private Memos
- steem-python for dummies #5 - Bundling Blockchain Operations
- steem-python for dummies #6 - Delegating
- steem-python for dummies #7 - Creating Accounts
- steem-python for dummies #8 - Calculating Post Rewards
- steem-python for dummies #9 - Creating orders in the market
- steem-python for dummies #10 - Listening accounts
- steem-python for dummies #11 - Listening new blocks
In this post, we will explore a couple of calls on steem daemon.
Discussions API
Do you know how Steemit filters the posts in the Condenser interface? Even though I didn't check it implicitly how they're doing, I am pretty much sure they're using discussions API in the steem daemon.
Getting Trending Posts
from steem import Steem
s = Steem()
query = {"limit": 5} # limit for 5 posts
for p in s.get_discussions_by_trending(query):
print("%s - %s" % (p["author"], p["permlink"]))
Let's check if that list matches with Steemit interface:
Tip: If you want to filter specific tags, just add a tag parameter to the query dict.
from steem import Steem
s = Steem()
query = {"limit": 5, "tag": "python"} # limit for 5 posts
for p in s.get_discussions_by_trending(query):
print("%s - %s" % (p["author"], p["permlink"]))
This will return last 5 trending posts on #python category.
All discussion related functions
- get_discussions_by_trending
- get_comment_discussions_by_payout
- get_post_discussions_by_payout
- get_discussions_by_created
- get_discussions_by_active
- get_discussions_by_cashout
- get_discussions_by_payout
- get_discussions_by_votes
- get_discussions_by_children
- get_discussions_by_hot
- get_discussions_by_feed
- get_discussions_by_blog
- get_discussions_by_comments
- get_discussions_by_promoted
All of these functions gets a query dict in steem-python which should map to original discussion_query struct defined at steemd database api.
So, after the first example about trending, you can pretty much use all functions with the same structure on query dict.
Tip: Currently, select_authors, select_tags, filter_tags arguments in discussion queries are not supported. See the related issue.
More examples
Promoted list
query = {"limit": 10}
for p in s.get_discussions_by_promoted(query):
print("%s - %s" % (p["author"], p["permlink"]))
By Highest Payout
query = {"limit": 10}
for p in s.get_discussions_by_payout(query):
print("%s - %s" % (p["author"], p["permlink"]))
Going back to history
Discussion filter has a maximum limit on limit parameter. It's 100. What if we want to go back?
It has a simple pagination logic.
- Get the initial 100 posts.
- Select the 100.post and keep in mind its author and permlink.
- Get another 100 posts, however add two more parameters. (start_author, start_permlink)
query = {
"limit": 10,
"start_author": "canadian-coconut",
"start_permlink": "the-nightmare-before-christmas-familyprotection-series-anna-s-family-story-part-i"
}
for p in s.get_discussions_by_trending(query):
print("%s - %s" % (p["author"], p["permlink"]))
canadian-coconut's this post is currently 10. place in the trending. If I start the query with that post, I will get the trending posts between 10 and 20.
That's all for now. Feel free to ask questions or request topics about steem-python for the incoming posts.
Posted on Utopian.io - Rewarding Open Source Contributors
Leave steem-python for dummies #12 - Lookups (Discussion Queries) to:
Read more #utopian-io posts
Best Posts From Emre
We have not curated any of emrebeyler's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.