Repository
https://github.com/steemit/steem-python
What Will I Learn?
Recently, several communities have emerged in steemit. Which is great news because this speaks of steemit going on the right track as a social network. Many of these communities follow objectives of mutual support or content curation. This process is not easy, it requires a considerable investment of time and at that time usually the elaboration of reports is added. The objective of this small tutorial is to provide a quick outline of how to automate this process.
In the following video, you will learn:
- How to prepare a program to publish curating reports automatically with Steem-python.
- How to extract the list of votes from a user.
- How to manipulate the information provided by the Steem API to establish filters with dates.
- How to post to the steem blockchain from steem-python.
Requirements
To be able to follow the following tutorial you need:
Python 3.6+
steem-python
Basic knowledge of programming in python
Difficulty
- Intermediate
Description
The first thing we will do is call the libraries that we will use. We will use libraries to manipulate dates with the intention of selecting a period of time of only one day. Thinking that the reports are made daily. Steem's Api returns all the information in UTC time zone, so we will use timezone to bring everything to our time zone. Finally we will import all the tools for steem that will allow us to interact with the blockchain.
from datetime import datetime,date
from datetime import timezone
from steem import *
For this tutorial we will use our private posting key within the initialization function. This is necessary since the program will post on the blockchain. We must also establish our account.
s = Steem(keys=['tlaloc-private-posting-key])
account='tlaloc'
To make a current day report we need to set our comparison date as the current date. If we want to use another date we will have to establish it consistently. We can also ask at runtime what the date of the report should be.
TodayReport = input('¿Deseas realizar un reporte de hoy?(s/n)')
if TodayReport == 's':
Report_date = datetime.today()
else:
Date = input('Introduce la fecha del reporte (Año/Mes/Día)')
Date = Date.split("/")
Report_date = date(int(Date[0]),int(Date[1]),int(Date[2]))
Now we will define the utc_to_local function. This will be responsible for replacing the UTC time zone with our local time zone.
def utc_to_local(utc_dt):
return utc_dt.replace(tzinfo=timezone.utc).astimezone(tz=None)
The essential elements to publish in steemit are title, body, author, permlink and tags. We will start with the title.
title='Reporte de curación del día ' + Report_date.strftime('%Y-%m-%d')
We have added the date of the report to the title so that each report has a unique title.
We will proceed to elaborate the body. Before going on to collect the curated publications, we can add a header or message to our publication.
body= ' Image + text ...'
body= body + '... text ....'
Important note, every time we add text to our body, we must rescue the previously prepared text.
For this example we will report the articles voted in a table with two headers: Author and Post.
body = body + '<table style="width:100%"><tr><th>Autor</th><th>Post</th></tr>'
HTML code is used for the layout.
We will use the get_account_votes method to ask the Api for all the votes made by our account.
Votes=s.get_account_votes(account)
With the votes we must filter those in the period of time that interest us. We must then go through each of the votes and identify which belong to the day of our interest.
for element in Votes:
Vote_date_utc = utils.parse_time(element['time'])
Vote_date = utc_to_local(Vote_date_utc)
if Vote_date.strftime('%Y%m%d') == Report_date.strftime('%Y%m%d'):
...
We have used the tool utils.parse_time. This tool converts the dates provided by Steem's Api into datetime objects, thanks to them we can manipulate it easily. After that we can change the time zone with the function we defined previously. Note that when comparing dates we only take into account year, month and day. Minor periods of time are not taken into account.
It's time to fill in our table. We will use the information 'authorperm' to extract the author and the permlink of each article. We will use this information as arguments of the get_content method that returns all the information of the article voted on.
if Vote_date.strftime('%Y%m%d') == Report_date.strftime('%Y%m%d'):
Author = element['authorperm'].split("/")[0]
Permlink = element['authorperm'].split("/")[1]
info=s.get_content(Author,Permlink)
I=info.get("json_metadata").find("https")
F=info.get("json_metadata").find('"',I)
Image=info.get("json_metadata")[I:F]
To extract the images we will look for the first string that contains "https" since in the metadata of each post the first addresses correspond to the images. These addresses always close with quotes ("
.) The images are not always attached in the metadata so we could perform a more exhaustive search in the body of the post, however for this first example we will settle for this.
Finally we will add the information to our table. In the first column we will write the author. In the second column we will write the title of the publication with a hyperlink to the post. The title is inside the extracted information with the get_content method.
body = body + '<tr><td>@{0}</td><td><center><a href="https://steemit.com/@{1}">{2}</a></center><center>{3}</center></td></tr>\n'.format(Author,element['authorperm'],info.get('title'),Image)
Outside the "for" cycle we will close the table. If we want to add some other text to our publication we must do it in this point.
body = body + '</table>'
body = body + 'goodbye to our article'
Now we are going to add the tags that we will use in our report. Each tag must be separated by a space.
taglist="spanish mosqueteros trail report curation"
We must now define the permlink of our publication. The permlink must be unique within our blog, therefore, we will also use the date of the report to define it.
permlink='reportedecuraciondeldia' + Report_date.strftime('%Y%m%d')
It is important to try to use only letters and numbers for the permlink.
As a last step we will send all the information to the blockchain to be published.
s.commit.post(title=title, body=body, author=account, tags=taglist, permlink=permlink)
If we want we can send a message to the console to indicate that the process has been successful.
print("Succes!")
That is all. When executing the program the article will be published automatically in the steem blockchain.
Video Tutorial
Source of the video thumbnail
Curriculum
You can find another videotutorial related in the following link:
Proof of Work Done
https://gist.github.com/Zenkly/27124569adfbad2bfe02a367e3cbb202
Hi @zenkly,
Thank you for your contribution. I see a little bit of improvement since the last time you contributed video tutorials.
Here are some suggestions for you:
Try to make your outline more clear with steps that learners can follow from one point to the other. There is no transition for your learner to know when you are moving on to the next step.
Use more instructional pointers for your learners so that they can stay focused on the point that you want to bring across.
Right now, your level of voice is monotone meaning that it demands the learner to really concentrate to understand each word that you are saying. You can practice reading your speech into a recorder, close your eyes and listen to the recording again. Ask yourself: do I sound boring? Do I have intonation of sounds? Do I motivate students with my voice? When you ask these questions, you will then find ways to move away from monotone and make your presentation more interesting and inviting.
Spend time to correct the grammar and flow of your written post.
Look forward to an improved presentation in your next submission.
Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.
To view those questions and the relevant answers related to your post, click here.
Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks, Rosa. I appreciate your feedback a lot, it gives me a good guide on how to improve.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
You are welcome @zenkly. Looking forward to your next contribution. :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you for your review, @rosatravels!
So far this week you've reviewed 5 contributions. Keep up the good work!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey @zenkly
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit