Fully Automated Steem Lottery [SOURCE CODE]

murh(60)
Published in
#steem
Words
55
Reading
1 min
Listen
Play
9y

As some of you know I'm running an automated lottery fasl@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 = ""
botadmin = ""
botgod = "murh"

botaccount = Account(botname)
botpostwif = ""
bottrnswif = ""

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"),"

Welcome to FASL - Fully Automated Steem Lottery [version %s_%s].

The rules are very simple:

  1. Transfer 1 STEEM to @fasl's account to buy a lottery ticket*.
  2. Every six hours a winner is chosen and will receive 97.5%-100%** of the @fasl's account balance.***

Have fun!

* One ticket per round per account. Ticket price is 1 STEEM.
** Refund in case of only one participant is 100%
*** 2.5% is transfered to @%s's and @murh's accounts for the R&D and bot's maintenance.

IF POSSIBLE, PLEASE UPVOTE AND RESTEEM.

"
% (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! ;)

Fully Automated Steem Lottery [SOURCE CODE] | Ecency