Programming with python on the steem blockchain-Lesson1- retrieve data from a community.
My first simple tutorial on how to programming with python on the steem blockchain is going to be about retrieving data from a community.
For this example, I will use steemskillshare community
Table of contents:
- Import the libraries
- Get the community description, and main accounts (admin, etc.)
- Get the list of subscribers
- Get the trending and last contents published
Before starting, I would like to invite you to read my first post and to book a private lesson or to publish a request in case you wish to learn something specific, about this topic.
1. IMPORT THE LIBRARIES
Python is a very flexible programming languages, and there are plenty of pre-coded libraries that allow you to start coding without starting from zero.
In this example, I'm going to use BEEM.
To import after the installation, simply type on you .py file:
from beem import Steem
In order to start to use the specific section to interact with communities, we need to import it:
from beem.community import Community
This is the absolute beginning, after that we must tell to our program to communicate with a node on the steem blockchain:
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_steem_nodes()
steem = Steem(node=nodes)
After this, we need to tell to the program which community we want to play with.
steem.skillshare community is hive-197809:
community = Community("hive-197809", blockchain_instance=stm)
This first step is done so the whole code is:
from beem.community import Community
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_steem_nodes()
steem = Steem(node=nodes)
community = Community("hive-197809", blockchain_instance=stm)
To test out everything went smooth, we can command to the program to print out the community:
print(community)
The output will be:
<Community hive-197809>
2. GET THE COMMUNITY DESCRIPTION AND MAIN ACCOUNTS
First of all let's see what information this library will give us by default, so after the previous last line we will create a list of all the variables that the community will give us:
for i in community:
print (i)
The output will be:
id
name
title
about
lang
type_id
is_nsfw
subscribers
sum_pending
num_pending
num_authors
created_at
avatar_url
context
description
flag_text
settings
team
So now we are interested in the team option, to read the data of this specific section we need this command:
print(community['team'])
The output:

As you can see here we got all the main accounts member and their role within the community.
Now let's put it in a more readable list:
x=1
for i in community['team']:
print (x,i)
x+=1
This is the output that shows us 13 team mebers and all the other infos:
1 ['hive-197809', 'owner', '']
2 ['milakz', 'admin', 'FOUNDER / 3000 SP Level 3']
3 ['daytona475', 'admin', 'Admin / Span Teacher/ PU level 2']
4 ['arie.steem', 'mod', 'Supervisor']
5 ['atim1234', 'mod', 'GRAPHIC/ Member / PU level2']
6 ['nastena09', 'mod', 'Russian Translator']
7 ['ftz', 'mod', 'Eng Teacher/ Member / PU level1']
8 ['endingplagiarism', 'mod', '']
9 ['papi.mati', 'mod', 'Polish Teacher']
10 ['slon21veka', 'mod', 'Mod / PU Level2']
11 ['steem.skillshare', 'mod', 'CURATION ACCOUNT']
12 ['dwarrilow2002', 'mod', 'Member / PU level 2']
13 ['jenesa', 'mod', 'Mod/PU Level 2']
Now we need the group description:
print(community['description'])
The output shows us all the description and infos the admin wrote about the group:
This Community focusses on letting the professionals and tutors meet
students and learners. You can teach any skill by writing your announcement
post. And steemians who are interested in learning can find you. If you are
a student who wants to find a teacher. You can also write your announcement
post.
https://discord.gg/yPQcgaUtzG
Here the whole code untill now:
from beem.community import Community
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_steem_nodes()
steem = Steem(node=nodes)
community = Community("hive-197809", blockchain_instance=stm)
for i in community:
print (i)
for i in community['team']:
print (x,i)
x+=1
print(community['description'])
3. GET THE LIST OF SUBSCRIBERS
First let's get the total number of subscribers:
print(community['subscribers'])
This command will return the total number, of course that now is 543
To get the number of active users:
print(community['num_authors'])
And finally let's get the last 250 subscribers list:
x=1
for i in community.get_subscribers():
print (x,i)
x+=1
The output will shows us the list with the name, the role, and the date of subscription:
1 ['msat', 'guest', None, '2021-08-10 11:58:27']
2 ['razuan12', 'guest', None, '2021-08-10 07:31:15']
3 ['tarilyn', 'guest', None, '2021-08-10 06:01:45']
4 ['hajiataiba', 'guest', None, '2021-08-10 00:05:54']
5 ['shohel44', 'guest', None, '2021-08-09 23:58:42']
6 ['viviandaniella', 'guest', None, '2021-08-09 16:25:39']
7 ['suglo100', 'guest', None, '2021-08-09 13:45:36']
8 ['sparta2021', 'guest', None, '2021-08-09 12:45:03']
9 ['solhwa', 'guest', None, '2021-08-09 11:59:36']
10 ['tymes2', 'guest', None, '2021-08-09 11:42:42']
....
Here the code so far:
from beem.community import Community
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_steem_nodes()
steem = Steem(node=nodes)
community = Community("hive-197809", blockchain_instance=stm)
for i in community:
print (i)
for i in community['team']:
print (x,i)
x+=1
print(community['description'])
x=1
for i in community.get_subscribers():
print (x,i)
x+=1
print('Total subscribers:',community['subscribers'])
print('Active users:',community['num_authors'])
4. GET THE TRENDING AND LAST CONTENTS PUBLISHED
This is the easiest in my opinion because it required just 2 lines, and the library will do the rest in sorting out the contents based on their popularity:
x=1
for i in community.get_ranked_posts():
print (x,i)
x+=1
It will return the last 100 posts sorted by popularity with all their data, content, and author.
This is the full code arranged in order to give a readable output:
from beem.community import Community
from beem.nodelist import NodeList
nodelist = NodeList()
nodelist.update_nodes()
nodes = nodelist.get_steem_nodes()
steem = Steem(node=nodes)
community = Community("hive-197809", blockchain_instance=stm)
x=1
for i in community.get_ranked_posts():
print (x,i)
x+=1
for i in community:
print (i)
for i in community['team']:
print (x,i)
x+=1
print(community['description'])
x=1
for i in community.get_subscribers():
print (x,i)
x+=1
print('Total subscribers:',community['subscribers'])
print('Active users:',community['num_authors'])
Thank you for such a valuable post. We already had few people who were searching for programming course. We will connect you with tgem
Thank you! Have you ever consider to set up your own domain and website?
Good post! Where can I see that programming? or is it just a sample you made in Beem ??
#affable