Getting Started With Steem-Python : Upvote and Comment Bot Examples (Linux)

in #esteem7 years ago

한국어로 번역하기

7개월 전

benniebanana51 insteemdev

Thanks to @libertyteeth , who pointed out a few minor errors in one of my early steem-python tutorials, I decided to do an updated version on how to get started with the steem-python library and share some code examples for doing a few different things on the blockchain. I will however not be going through the process of setting up your Python environment but you're welcome to have a look at the following tutorial on how to set up your environment in Ubuntu.
image
Setting up your environment in Linux(Ubuntu). Link

This is just one tutorial I found online but feel free to use any other tutorial you can find as long as you have at least Python 3.5 and pip

Awesome! Let's get started

First off we need to get the steem-python library so lets run the following command to get it:

$ pip install steem

I'll be using the Geany editor. If you want to use Geany you can run the following command to get it or you could use any other text editor of your choice.
image
$ sudo apt-get install geany

Next we'll create and open our python file where we'll be coding:

$ geany filename.py

From here on I'll be sharing two code examples I wrote on how to do different things on Steemit and the Steem blockchain including a bot that upvotes posts and comments mentioning us as well as n welcoming bot.

image

source

Upvoting comments and posts that mention us

from steem import Steem from steem.blockchain import Blockchain from steem.post import Post #crate steem instance and pass it our key s = Steem(keys = [""]) #create blockchain instance b = Blockchain() #stream the blockchain, map it to a Post object to make life easier and filter #them by comment since all comments and posts are of type: comment stream = map(Post, b.stream(filter_by=['comment'])) #go through all the posts in the block for post in stream: try: #get all the users tagged in the post users = post.json_metadata.get('users', []) #check if we are tagged if "<your-steemit-username-in-lowercase>" in users: #if we are tagged we'll upvote the post/comment with 10% voteweight post.vote(10.0, "") else: #we are not tagged so we will skip this post pass except Exception as e: print("Error: "+str(e))

Welcoming new people to Steemit with a comment bot

image
from steem import Steem from steem.blockchain import Blockchain from steem.post import Post #create steem instance and pass it our key s = Steem(keys = [""]) #create blockchain instance b = Blockchain() while True: try: # stream the blockchain stream = map(Post, b.stream(filter_by=['comment'])) # go through all the posts in the block for post in stream: # get all the tags of the post postTags = post.json_metadata.get('tags', []) # check if "introduceyourself" is in the list of tags if "introduceyourself" in postTags: title = post.title # check if the post/comment has a title if title == "": #title is empty so it's most likely a comment pass else: #We have a title so it's a fresh posts so let's welcome them post.reply("Welcome to Steemit!", "", "") else: #no introduceyourself tag so skip the post pass except Exception as e: print("Error: "+str(e))

To run any one of these scripts you can issue the following command:
$ python3 filename.py

Please Note

I don't advice anyone to actually use these. These are merely just examples of how you could implement the steem-python library. Each of these have their own problems which I did not fully address. I also doubt that these examples follow the best coding practice. Here are some of the problems:

  • Upvote Bot

If people realise that you're upvoting any comment or post with your name in it people might abuse it and spam your name for a free upvote.

  • Comment Bot

A lot of people abuse the introduceyourself tag because it's one of the tags with the highest amount of payouts. There are also loads of people running welcoming bots which turns into spam and people don't take to kindly to that so you'll most likely get flagged if you do the same. Bots can also programmatically add titles to their comments so checking if the title is empty or not in order to determine if it's a post or a comment is not the best way to go about it.

  • Other things to keep in mind

As far as I know Steemit only allows you to upvote every 3 seconds and comment every 20 seconds

For the full Steem-Python documentation you can visit this Link.

Please let me know if you spot an error so I can fix it as soon as possible. Feel free to ask questions in the comments. I hope you found this tutorial helpful.

steemdevsteem-devtutorialdevelopmentpython

7개월 전 by benniebanana51

$79.18

107 votes

댓글 남기기 13 34

Sort Order: trending

한국어로 번역하기

[-]

afm00749 · 지난달

I wanna give a try. Though I'm not a professional coder let's start it give it a try.

$0.08

2 votes

댓글 남기기

한국어로 번역하기

[-]

sn0w-fox42 · 4일 전

great tutorial @cleverbot

$0.01

1 vote

댓글 남기기

한국어로 번역하기

·

[-]

cleverbot47 · 4일 전

Never Gonna Give you up(Rick Roll'd).

$0.00

댓글 남기기

한국어로 번역하기

[-]

booster58 · 7개월 전

This post has received a 0.87 % upvote from @boosterthanks to: @banjo.

$0.00

댓글 남기기

한국어로 번역하기

[-]

joserc.vzla46 · 7개월 전

Excellent follow me @ joserc.vzla

$0.00

댓글 남기기

한국어로 번역하기

[-]

dewallenband55 · 7개월 전

Great post man, would love to try this when I get Linux.

$0.00

댓글 남기기

한국어로 번역하기

[-]

greenacrehome55 · 7개월 전

Hey @benniebanana, I'm trying to install steem and get an error that python 3.5 or newer is required and this error: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gQWp0C/steem/

Running python -v reveals Python 3.6.1 :: Anaconda 4.4.0 (32-bit)

Any suggestions? Thanks

$0.00

댓글 남기기

한국어로 번역하기

·

[-]

benniebanana51 · 7개월 전

Hi sorry for the very late reply. Unfortunately I have never had that error. I'll have a look around and let you know if I find something useful unless you've already figured it out?

$0.00

댓글 남기기

한국어로 번역하기

·

·

[-]

greenacrehome55 · 7개월 전

I've not yet. Thanks

$0.00

댓글 남기기

한국어로 번역하기

[-]

kmulan39 · 4개월 전

Nice post! Thanks for making this. It aided me in a way. :)

$0.00

댓글 남기기

한국어로 번역하기

[-]

therecantonlybe136 · 2개월 전

I am really new to coding. I was wondering if it was possible to deploy these upvote and comment bots through Heroku?

$0.00

댓글 남기기

한국어로 번역하기

[-]

solomon12337 · 지난달

I still don't understand something about this API although i haven't put it in action, I've been to the steemit documentation before seeing your post

from steem import Steem
from steem.post import Post
#Here we are importing the required libraries needed for this task

s = Steem(keys = ["your private posting key"])
#so here we created a steem instance with our private posting key, i also noticed it's a list why ?

post.vote(10.0, "your steemit username")
#we just skipped to the post function, does the post.vote(float, string) just link from the instance to use your account to post

Also what if i want to upvote a particular vote by supplying its link

I know there are lots of errors here :)

$0.00

1 vote

댓글 남기기

한국어로 번역하기

[-]

spencercoffman61 · 6시간 전

I've been having a terrible time trying to get a bot going. I have a string of code and have changed it so many times to try to fix the errors that come up I don't even know what I'm doing anymore. I never knew what I was doing to begin with :)

Anyway, I was trying to create an upvote bot that anyone could use.
Now, I'd like to create a bot that will comment for me on intro posts. Any chance you could help me with this?

$0.00

댓글 남기기

Sort:  

No I don't know Japanese.

If I can cut down trees using your muscle machine.

Coin Marketplace

STEEM 0.27
TRX 0.20
JST 0.038
BTC 97065.72
ETH 3594.48
USDT 1.00
SBD 3.94