THE MACHINE THAT GOES 'PING' [v0.0.4]

in #steem8 years ago

So, we meet again ;) The machine/bot now knows who it talks to and can provide information about other users than itself.

Here's the code for it:

import time
from sys import stdout

from steem import Steem
from steem.account import Account

ver = "0.0.4"

usr = "tpos"

acc = Account(usr)
wif = "5tH1sI50bVioU5lYaF4K3vv1Fk3yh0w3vEr17rieD2m4kEits0e"

def f_balance():
	return "Pot's current balance is %s (%s CEST)" % (acc.balances["STEEM"],time.strftime("%Y.%m.%d %H:%M:%S"))

def f_version():
	return "TMTGP version %s" % ver

def f_tellmyname():
	return "Your name is %s." % currentpost["author"]

def f_tellmybalances():
	currentaccount = Account(currentpost["author"])

	return "Your currently have %s and %s. You have %s. Your savings accounts hold %s and %s." % (currentaccount.balances["STEEM"],currentaccount.balances["SBD"],currentaccount.balances["VESTS"],currentaccount.balances["SAVINGS_STEEM"],currentaccount.balances["SAVINGS_SBD"])

commandlist = {
	"tpos:BOT_VERSION": f_version,

	"tpos:POT_BALANCE": f_balance,

	"tpos:TELL_MY_NAME": f_tellmyname,
	"tpos:TELL_MY_BALANCES": f_tellmybalances,
}

steem = Steem(keys=[wif])

print("[ \033[33mTHE MACHINE THAT GOES 'PING'.\033[0m v%s ]" % ver)

for post in steem.stream_comments():

	try:
		stdout.write(".")
		stdout.flush()

		for command in commandlist:

			if command in post["body"]:

				stdout.write(". ")
				stdout.flush()

				currentpost = post

				try:

					post.reply("%s" % commandlist.get(command)()," ","%s" % usr)
					time.sleep(20)
					stdout.write("\033[32mPING\033[0m ")
					stdout.flush()

				except:

					stdout.write("\033[31mF00K\033[0m ")
					stdout.flush()
	except:
		
		stdout.write(" \033[31m5H17\033[0m ")
		stdout.flush()

Enjoy ;)

Sort:  

v0.04 HELP:

tpos:BOT_VERSION
tpos:POT_BALANCE
tpos:TELL_MY_NAME
tpos:TELL_MY_BALANCES

Your name is murh.

Pot's current balance is 1085.042 STEEM (2017.02.16 00:48:19 CEST)

TMTGP version 0.0.4

Your currently have 0.163 STEEM and 0.027 SBD. You have 2522558.552695 VESTS. Your savings accounts hold 0.000 STEEM and 0.000 SBD.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 62227.11
ETH 2400.78
USDT 1.00
SBD 2.50