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

steem-python.png

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

Screenshot 2018-01-18 12.03.34.png

Curriculum

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

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now