Part 7: How To Schedule Posts And Manually Upvote Posts For A Variable Voting Weight With Steem-Python

This tutorial is part of a series where different aspects of programming with steem-python
are explained. Links to the other tutorials can be found below. This part is a direct continuation on Part 5: Post An Article Directly To The Steem Blockchain And Automatically Buy Upvotes From Upvote Bots where you learned how to directly post an article to the Steem blockchain. This tutorial will expand on this by explaining how to schedule your post on certain times and use a variable vote on your own article.
What will I learn
- How to schedule your posts
- How to upvote a post with a variable weight
Requirements
- Python 3.6
steem-python
Difficulty
- Basic
Tutorial
Set up
Start by downloading all the files from github. There are a total of 3 files, post.txt
is used to store the body of the post, schedule.json
is used to configure the schedule for the posts and can be altered even when the application is running and scheduler.py
is the application which will run 24/7.
The application works by loading schedule.json into memory every hour. It then checks if a post is scheduled at that hour and posts this to the blockchain. The post is also upvoted for the set upvote weight. To prevent reposts the submitted post is removed from the schedule and the file is updated to the hard drive.
How to schedule your posts
In schedule.json
you can add a dict containing the data needed to schedule the post. The key itself is the time in hours when the post has to be submitted. Further there is a title, upvote_weight, tags and a filename to the body of the post.
"13": {
"title": "Testing scheduler",
"upvote_weight": 80,
"tags": "bot test programming python",
"filename": "post.txt"
}
Note: The application is put to sleep for 60 seconds each cycle to preserve CPU resources.
How to upvote a post with a variable weight?
In the previous tutorial we submitted the post directly to the blockchain with self_vote
set to True
. This automatically upvotes the post but also always upvotes the post for 100%. Instead setting self_vote
to False
allows for a manual upvote with a variable upvote weight.
def post(self,
title,
body,
author,
permlink=None,
reply_identifier=None,
json_metadata=None,
comment_options=None,
community=None,
tags=None,
beneficiaries=None,
self_vote=False):
Calling the post function to submit the post then looks like:
steem.post(title, body, author, permlink, None, None, None, None, tags, None, False)
The vote function has the following structure, where the identifier is made up by the author and the permlink we created (explained in the previous tutorial).
def vote(self,
identifier,
weight,
account=None):
Manually upvoting the post for upvote_weight then looks like:
steem.vote('@{}/{}'.format(author,permlink), upvote_weight, author)
Running the code
Configure the author
variable to your own account, alterpost.txt
with the post you want to post and set its meta data in schedule.json
, including the time at which it has to be posted.
python scheduler.py
Submitted post
Removed entry from schedule
Saved file to harddrive
Curriculum
- Part 0: How To Install Steem-python, The Official Steem Library For Python
- Part 1: How To Configure The Steempy CLI Wallet And Upvote An Article With Steem-Python
- Part 2: How To Stream And Filter The Blockchain Using Steem-Python
- Part 3: Creating A Dynamic Upvote Bot That Runs 24/7
- Part 4: How To Follow A Voting Trail Using Steem-Python
- Part 5: Post An Article Directly To The Steem Blockchain And Automatically Buy Upvotes From Upvote Bots
- Part 6: How To Automatically Reply To Mentions Using Steem-Python
Credits
This tutorial was written by @juliank in conjunction with @amosbastian
The code for this tutorial can be found on GitHub!
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Appreciated as always :D
Cool!
Instead of keeping the timing logic inside the python script you could use a tool like at on Linux and Mac. Then you wouldn't have to update the JSON each time you want to schedule a new script or worry that a failed earlier post would impact a later post.
wow, at command looks very good.
Awesome, thanks I will have a look at it
Great!
Can you also consider writing a tutorial about how to create posts with beneficiaries?
Surely can, will look into this as I have never used this before. Thanks for the tip!
I like your post as succesful as always
one of the best language for computer programmers to work on
Thank you sharing....
Hey @steempytutorials I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x