This tutorial will explain and show you how to access the Steem blockchain using the steem-python library to fetch list of posts and get replies info on selected post.
Intro
Steem python library has built-in function to get active voters information if post with author and permlink as an argument. Since we don’t have predefined post or author/permlink. We will fetch post list from previous tutorial and give option to choose one post to get its active voters. get_content_replies function fetches list of replies on content. Note that get_discussions_by_hot filter is used for fetching 5 posts and after selection of post tutorial uses author and permlink of the post to fetch replies.
In this tutorial we use 3 packages, pick - helps us to select filter interactively. steem - steem-python library, interaction with Blockchain. pprint - print results in better format.
First we import all three library and initialize Steem class
importpprintfrompickimportpick# initialize Steem class
fromsteemimportSteems=Steem()
2. Post list
Next we will fetch and make list of posts and setup pick properly.
query={"limit":5,#number of posts
"tag":""#tag of posts
}#post list for selected query
posts=s.get_discussions_by_hot(query)title='Please choose post: 'options=[]#posts list options
forpostinposts:options.append(post["author"]+'/'+post["permlink"])# get index and selected filter name
option,index=pick(options,title)
This will show us list of posts to select in terminal/command prompt. And after selection we will get index and post name to index and option variables.
3. Replies list
Next we will replies on selected post with get_content_replies.
# get replies for given post
replies=s.get_content_replies(posts[index]["author"],posts[index]["permlink"])
4. Print output
Next, we will print result, replies on selected post, selected post details and number of replies.
# print post details for selected post
pprint.pprint(replies)pprint.pprint("Selected: "+option)pprint.pprint("Number of replies: "+str(len(replies)))
The example of result returned from the service is a JSON object with the following properties:
From this result you have access to everything associated to the replies including content of reply, author, timestamp, etc., so that you can be use in further development of application with Python.
PY: Get Post Comments
Fetch comments made on each content or post using Python.
Full, runnable src of Get Post Comments can be downloaded as part of the PY tutorials repository.
This tutorial will explain and show you how to access the Steem blockchain using the steem-python library to fetch list of posts and get replies info on selected post.
Intro
Steem python library has built-in function to get active voters information if post with author and permlink as an argument. Since we don’t have predefined post or author/permlink. We will fetch post list from previous tutorial and give option to choose one post to get its active voters.
get_content_replies
function fetches list of replies on content. Note thatget_discussions_by_hot
filter is used for fetching 5 posts and after selection of post tutorial usesauthor
andpermlink
of the post to fetch replies.Steps
1. App setup
In this tutorial we use 3 packages,
pick
- helps us to select filter interactively.steem
- steem-python library, interaction with Blockchain.pprint
- print results in better format.First we import all three library and initialize Steem class
2. Post list
Next we will fetch and make list of posts and setup
pick
properly.This will show us list of posts to select in terminal/command prompt. And after selection we will get index and post name to
index
andoption
variables.3. Replies list
Next we will replies on selected post with
get_content_replies
.4. Print output
Next, we will print result, replies on selected post, selected post details and number of replies.
The example of result returned from the service is a
JSON
object with the following properties:From this result you have access to everything associated to the replies including content of reply, author, timestamp, etc., so that you can be use in further development of application with Python.
That’s it!
To Run the tutorial
cd tutorials/07_get_post_comments
pip install -r requirements.txt
python index.py