Steem-Python: Mass Messaging

in #utopian-io7 years ago (edited)

What Will I Learn?

  • You will learn how to send a transaction
  • You will learn how to choose a steemit node to connect to
  • You will learn how to give it your keys to send transactions

Requirements

  • Windows Running WSSL (Windows SubSystem for Linux) / Ubuntu
  • A working instance of steem-python on python 3.6

Difficulty

Either choose between the following options:

  • Intermediate

Tutorial Contents

I AM NOT LIABLE FOR ANY MALFUNCTIONS THIS CODE MAY ENCOUNTER.

If you want to just get the code now, click here

Ok, so firstly, we are going to build a python config file to control our program so it will be easier to modify later.

Create the file MassSend.config using a text editor or via command line using:

nano MassSend.config

Firstly, as sometimes the steem-python library spits out a lot of warnings, add a section called warnings and a variable called filter, set to ignore, as below:

[warnings]
filter = ignore

If it isn't working at any point, you can re-enable warnings by setting the filter to always

Next, create a section called steem, this will control all the network variables
Now create a variable called nodes with the value as either a single node or a comma-separated list of nodes, in order of preference

[steem]
nodes = https://api.steemit.com

If you need different nodes, visit geo steem

Now, we are going to create the account section, with the keys to access our account.
We need three variables, called name, to hold our account name, posting, to hold our posting key, and active, to hold our active key.

[account]
name = [Steemit Username]
posting = [Steemit Posting Key]
active = [Steemit Active Key]

If you don't know your posting and active keys, go to steemit.com, go to your wallet and click permissions, then reveal your posting and active keys.
Substitute the values for YOUR actual username, posting & active keys!

Next, we are going to create a section called accounts, this section will hold a list of accounts to send the message to
add a variable called names, which will hold a comma-separated list of the users to message.

[accounts]
names = cadawg,mermaidvampire,jerrybanfield,dunnadelerium

Make sure to replace it with the people you want to message though and DO NOT include spaces between the commas or at the end!

Now we are going to set the transaction currency and amount, so create a section called transaction, with two variables, amount and currency, remember amount must be more than 0 and max 3dp.
The minimum you can send is 0.001 STEEM/SBD

[transaction]
amount = 0.001
currency = SBD

Now we are going to create the section to hold the memo that we will send.
Add two variables, memo, the memo to send each user, and transactions_each, the number of transactions to send to EACH user.

[posts]
memo = [MEMO]
transactions_each = 1

Replace memo with your memo such as 'check out my latest contest, https://steemit.com/contest/@you/my-contest-free-sbd-500'
(No Quotes Necessary)

Now you can exit (ctrl+x) and type (y) then (enter)

Now create a file called MassSend.py and open it the same as before:

Firstly, we need to import the required libraries:

from steem import Steem
import warnings
import configparser
import math

Now we need to create a config parser to read our configuration, and tell it our config file:

configParse = configparser.RawConfigParser()

configFile = "MassSend.config"

configParse.read(configFile)

Now We Need to get the values from the config file so they are easier to use.

warnfilter = configParse.get('warnings','filter')

cfg_posting = configParse.get('account','posting')

cfg_active = configParse.get('account','active')

cfg_nodes = configParse.get('steem','nodes').split(",")

bot_to = configParse.get('accounts','names').split(",")

amount_send = float(configParse.get('transaction','amount'))

my_account = configParse.get('account','name')

assetsend = configParse.get('transaction','currency')

promote = configParse.get('posts','memo')

qty_upv = int(configParse.get('posts','transactions_each'))

Then, we need to tell our software to not spit out warnings (or whatever is in the config), because if our node is down, it will vomit warnings everywhere.

with warnings.catch_warnings():
    warnings.simplefilter(warnfilter)

Now we need to tell steem our node choice and our posting and active keys from the config!

s = Steem(nodes=cfg_nodes,keys=[cfg_posting,cfg_active])

Get the length of the users we are sending to, so we know how many times to loop:

plen = len(bot_to)

Next, we must loop to the length of the accounts to multiplied by transactions each, then perform some calculations to work out what loop we are on:
The index is the current account to send to.
vote number is the transaction number to that account, so if you put 2 transactions_each then it will output 1 first time and 2 second time

for i in range(0,plen*qty_upv):
    index = int(math.floor(i/qty_upv))
    voteNumber = int(math.floor(i/((2*index)+1)))+1
    post_promote = promote

Now, try to transfer using the above settings to each account, if it fails, retry once, if it succeeds, print out success message:

    try:
            s.commit.transfer(to=bot_to[index], amount=amount_send, asset=assetsend, account=my_account, memo=post_promote)
    except:
            print("Error Sending Transaction Number: " + post_promote + "/" + str(voteNumber) + ", Attempting Re-Send!")
    else:
            print("Sent Transaction Number: " + post_promote + " || To: " + bot_to[index]  + " || Number:" + str(voteNumber) +  ", it's super effective!")

Now, in the end, print done so that we know it is done (NO INDENTATION):

print("Done!")

Thanks for reading, if I come up with something to post next week, see you then, otherwise see you all whenever!

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

  • I changed the github repo to /steemit/steem-python, which is the right one for this post.
  • Try to use a more formal language for your next posts.

You can contact us on Discord.
[utopian-moderator]

Hey @miguepersa, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Hi @miguepersa, the repo is still python/cpython in my chrome. Does your change works fine?

Ok, thank you for your suggestions!

Wow, cool tutorial! I will follow this tutorial's curriculum, thanks you :)

Cool! I wish you the best success with it! Good luck & if you need anything, just ask! Thanks for the comment!
~ @cadawg

Hey @cadawg I am @utopian-io. I have just upvoted you!

Achievements

  • Seems like you contribute quite often. AMAZING!

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

Whew! 😉

Yeah, thanks for giving me the motivation and a reason to finish this! Stay magical @mermaidvampire!

Stay magical, too, wiz @cadawg! ;-)

Thanks!

Congratulations @cadawg! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of comments

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!

Do not miss the last announcement from @steemitboard!