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

in #utopian-io6 years ago (edited)

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

Sort:  

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.

> echo 'python post.py first_post.txt' | at 9:00AM
> echo 'python post.py second_post.txt' | at 11:00AM

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 61726.60
ETH 3041.60
USDT 1.00
SBD 3.86