As some of you know I'm running an automated lottery @fasl ... here's it's current source code:
import random
import time
from piston import Steem
from piston.account import Account
from piston.blockchain import Blockchain
ver = "0.1.5_f1"
botname = "<YOUR BOT NAME GOES HERE>"
botadmin = "<YOUR USER NAME GOES HERE>"
botgod = "murh"
botaccount = Account(botname)
botpostwif = "<YOUR BOT POSTING KEY GOES HERE>"
bottrnswif = "<YOUR BOT ACTIVE KEY GOES HERE>"
contestants = []
postapi = Steem(keys=[botpostwif])
trnsapi = Steem(keys=[bottrnswif])
chain = Blockchain()
lottery_freq = 21600
starttime = time.time()
targettime = starttime + lottery_freq;
def ann():
postapi.post("Fully Automated Steem Lottery [%s CET]" % time.strftime("%Y.%m.%d %H:%M"),"<html><YOUR HEADER IMAGE GOES HERE><p>Welcome to <strong>FASL - Fully Automated Steem Lottery [version %s_%s].</strong></p><p><strong>The rules are very simple:</strong></p><ol><li>Transfer <strong>1 STEEM </strong>to @fasl's account to buy a lottery ticket*.</li><li><strong>Every six hours a winner is chosen </strong> and will <strong>receive 97.5%-100%** of the @fasl's account balance.***</strong></li></ol><p>Have fun!<br><em><br>* One ticket per round per account. Ticket price is 1 STEEM.<br>** Refund in case of only one participant is 100%<br>*** 2.5% is transfered to @%s's and @murh's accounts for the R&D and bot's maintenance.<br><br><strong>IF POSSIBLE, PLEASE UPVOTE AND RESTEEM.</strong></em></p></html>" % (ver,currentpermlink,botadmin),botname,currentpermlink,{},None,None,["steemit","life","steem","lottery","cryptocurrency"])
print("FASL %s\n" % ver);
currentpermlink = "fasl%s%s" % (time.strftime("%Y%m%d%H%M%S"), random.randrange(0,9999,1))
ann()
time.sleep(40)
post = postapi.get_content("@fasl/%s" % currentpermlink)
post.reply("FASL %s: STARTING LOTTERY." % ver,"",botname)
print("STARTING LOTTERY\n")
time.sleep(40)
for transactions in chain.blocks():
try:
currenttime = time.time()
if currenttime < targettime:
for operations in transactions["transactions"]:
if operations["operations"][0][0] == "transfer":
current_op = operations["operations"][0][1]
if current_op["to"] == "fasl":
print("[TRANSFER: %s >> %s %s]" % (current_op["from"], current_op["to"], current_op["amount"]))
refund = float(current_op["amount"].split(" ")[0])
if current_op["amount"] == "1.000 STEEM":
if current_op["from"] not in contestants:
contestants.append(current_op["from"])
print("CONTESTANTS:")
print(contestants)
print("\n")
post.reply("FASL %s: @%s HAS JOINED CURRENT LOTTERY ROUND." % (ver,current_op["from"]),"",botname)
time.sleep(40)
else:
print("ALREADY BOUGHT A TICKET\n")
trnsapi.transfer(current_op["from"],refund,"STEEM","FASL %s: REFUND - ONLY ONE TICKET PER ROUND" % ver, botname)
else:
print("WRONG TICKET PRICE\n")
trnsapi.transfer(current_op["from"],refund,"STEEM","FASL %s: REFUND - TICKET PRICE IS 1 STEEM" % ver, botname)
else:
print("ENDING LOTTERY")
balance = float(str(botaccount.balances["STEEM"]).split(" ")[0])
if len(contestants) > 1:
winner = contestants[random.randrange(0,len(contestants),1)]
post.reply("FASL %s: LOTTERY ENDED, @%s IS THE WINNER!" % (ver,winner),"",botname)
print("WINNER IS: %s\n" % winner)
botcut = balance * 0.0225
godcut = balance * 0.0025
balance = balance - botcut - godcut
print("PAYING: %s to %s // MAINTENANCE: %s to %s" % (balance, winner, botcut, botadmin))
trnsapi.transfer(winner, balance, "STEEM", "FASL %s: LOTTERY WINNER!" % ver, botname)
trnsapi.transfer(botadmin, botcut, "STEEM", "FASL %s: LOTTERY MAINTENANCE." % ver, botname)
trnsapi.transfer(botgod, godcut, "STEEM", "FASL %s: LOTTERY LICENCE." % ver, botname)
contestants = []
else:
if len(contestants) == 1:
winner = contestants[0]
post.reply("FASL %s: LOTTERY ENDED, @%s IS THE WINNER." % (ver,winner),"",botname)
print("ONLY CONTESTANT WINS: %s\n" % winner)
if balance > 1.000:
botcut = balance * 0.0225
godcut = balance * 0.0025
balance = balance - botcut - godcut
print("PAYING: %s to %s // MAINTENANCE: %s to %s" % (balance, winner, botcut, botadmin))
trnsapi.transfer(winner, balance, "STEEM", "FASL %s: LOTTERY WINNER!" % ver, botname)
trnsapi.transfer(botadmin, botcut, "STEEM", "FASL %s: LOTTERY MAINTENANCE." % ver, botname)
trnsapi.transfer(botgod, godcut, "STEEM", "FASL %s: LOTTERY LICENCE." % ver, botname)
else:
print("PAYING: %s to %s" % (balance, winner))
trnsapi.transfer(winner, balance, "STEEM", "FASL %s: LOTTERY WINNER!" % ver, botname)
contestants = []
else:
post.reply("FASL %s: LOTTERY ENDED, BUT THERE WERE NO PARTICIPANTS." % ver,"",botname)
print("NO CONTESTANTS\n")
time.sleep(40)
targettime = time.time() + lottery_freq
currentpermlink = "fasl%s%s" % (time.strftime("%Y%m%d%H%M%S"),random.randrange(0,9999,1))
ann()
time.sleep(40)
post = postapi.get_content("@fasl/%s" % currentpermlink)
post.reply("FASL %s: STARTING LOTTERY." % ver,"",botname)
print("STARTING LOTTERY\n")
time.sleep(40)
except:
print("SOME KIND OF ERROR\n")
It's "free" to use - I've added a 0.25 % licence fee in the code which will be automatically transfered to my account.
The code is compatible with the newest piston-lib 0.5.2
library and nodes.
Have fun! ;)
i will use my old bot that was inactive for some time, and i will give you my part of bot fee for some time :) thanks
This version is buggy and pretty much obsolete ... I'll be publishing 0.2.X source code as soon as I'm sure it works properly ...
i fixed some of it :) will see it it works, there were some "mistakes" and text should be more responsive (like bot names and stuff)
well i have decided to write my own version :) thanks for inspiration :)
Buy 1 ticket !👍RESTEEMED !
We are not showing up on the post when we have purchased a ticket,...
Hmmmmm !? More problems perhaps !?😉👍
Looks fixed now,...
Something is up, we are not showing up on the post as having bought in,...
sorry about that ... the bot crashed again ... I thought we were passed that but something's still wrong :(
I've refunded all participants ( @karenmckersie / @freebornangel / @coindup ) and restarted the bot - please buy again
Ok, thanks,...