Python - Magic Dice Roller ๐ฒ
utopian-ioยท@aro.steemยท
0.000 HBDPython - Magic Dice Roller ๐ฒ
#### Repository
https://github.com/nnmix/py-magicdice-bot
#### What Will I Learn?
- You will learn to automate a @magicdice Bot given your own rules
- You will learn to use Steem - Python Lib
- You will learn to program your own 'Rule Based' dice rolls
[](https://magic-dice.com/?ref=aro.steem)
#### Requirements
##### Personal Prerequisite
- **Existing** [STEEM Account](https://www.steemit.com/)

##### System prerequisites:
- [Jupyter](https://jupyter.org/) notebook for python
##### Knowledge prerequisites:
- Basic understanding of python programming
#### Difficulty
- Intermediate
#### Description
In this tutorial you will get the ability to automate your own flavored Dice Roller Bot for @magicdice on STEEM
#### Content
Before getting to the python scripting section you will need a STEEM account token to be used.
##### 1. STEEM Account - Private Active Keys
##### 2. Jupyter / Python
* You can access Jupyter [Online](https://jupyter.org/try) or [Intall](https://jupyter.org/install.html) it locally on your PC
* When done open a new python file: 
* When the file is open, if you are on the online version, you can delete existing sample cell by clicking the cell border (blue highlight) than double pressing 'D'

Until you have an empty cell to write your script within:

* Now your jupyter editor is up you can start typing your code and run it by pressing **ctrl+enter**
##### 3. [Magic Dice](https://magic-dice.com/?ref=aro.steem) Roller/ Python
Let us start talking about the magicdice roller implementation
* Using [Python Steem Lib](https://steem.readthedocs.io/en/latest/install.html) (pip install steem)
* First Doing The Dice Roll by sending a transaction with Memo inside containing
- the bet STEEM amount
- the target with 'under' or 'over'
- the client rand seed which is a sha256 of a random of length 10


* Then Wait For An Incoming Transaction Result From Magic Dice:

````
# Magic Dice Roll Script Sample
# Replace <private active keys by yours>
from steem import Steem
import hashlib, binascii, random, time
def randhash():
m = hashlib.sha256()
m.update((str(random.randint(1,101)*time.time())).encode('utf-8'))
m.update((m.hexdigest() + str(random.randint(1,101))).encode('utf-8'))
x = m.hexdigest()
return x[2:12]
def newTx(s, amount, direction, target):
randh = randhash()
query = "{0} {1} {2}".format(direction, target, randh)
s.commit.transfer('magicdice',amount,'STEEM', memo = query, account="aro.steem")
return randh
def roll(steem, amt) :
randh = newTx(steem, amt, 'under', 30)
txId = '-1'
won = 0
randh = str(randh)
# wait for the tx id
while True :
dta = steem.get_account_history('aro.steem', index_from=-1, limit=20)
for i in range(len(dta)):
dd = dta[i][1]
if dd['op'][0] == 'transfer' and dd['op'][1]['to'] == 'magicdice' and dd['op'][1]['memo'].find(randh) > -1:
txId = str(dd['trx_id'])
break
if str(txId) != '-1':
break
time.sleep(2)
# wait for the result
while True :
dta = steem.get_account_history('aro.steem', index_from=-1, limit=20)
for i in range(len(dta)):
dd = dta[i][1]
if dd['op'][0] == 'transfer' and dd['op'][1]['from'] == 'magicdice' and dd['op'][1]['memo'].find(txId) > -1:
if dd['op'][1]['amount'] == '0.001 STEEM':
won = -1
else:
won = 1
break
if won != 0:
break
time.sleep(2)
return txId, won, randh
s = Steem(keys=["<private active keys>", "<private active keys>"])
st = time.time()
# do one dice roll
txId, won, randh = roll(s, 0.1)
et = time.time()
# show results: wait time, transaction Id, win as 1 and lost as -1
print(et - st, txId, won)
````
#### The End!
Finally most of the steps are covered, it is your time to configure your own rules / algorithm that may give you your optimal winning payouts.
**Feel free** to share and list your own automation python bot script on the project github project page with your fresh good results for others to try !
#### Related
- [My steemit announcement: https://steemit.com/utopian-io/@aro.steem/dice-roller-bot-python-primedice)
#### Proof of Work Done
https://github.com/nnmix/py-magicdice-bot/blob/master/script.py
๐ sergino, bluesniper, ezravandi, efficientseptum, katerinakarim, gracefulestrogen, wombtick, friedradius, celsiusdelete, bountyx2, ikalinowski, berwynelbow, embryofemur, salyese, sesurick, orallu, lontesl, lurdofro, ederonde, agalte, yalotin, itamow, leir, espoem, mops2e, ascorphat, amosbastian, rufans, helo, jaff8, bestofph, tobias-g, codingdefined, ulockblock, mcfarhat, busy.org, themarkymark, aro.steem, indayclara, portugalcoin, bejust, feronio, progressing, steem-ua, newsrx, sargoon, mariita52, lostmine27, utopian-io, tombstone, jga, cryptouno, swapsteem, fusionnuclear, exbroker, loraanasta, mariappan, upbitstemhot, chrstnv, sanekabir, evananisa, podah, soulinsiders, andymoonpie, yhaulez, micaldaviddin, tejacode, tblaze, enny-b, ziuntown, maikellelcrack, fatany, abubakarefty, dippa, kartheekh, riazuddin101, olusamex, thecryptoboy, dewidewi, fortunesteem, yogiyo, treasoner13, jesusmarin18, dassvollkornbrot, kecap, jima, renat242, nairamallam, votezilla, luckyjuly24, johannesbaumer, ubik, aponkl, franklin001233, indronill, recetopolitico, sadiajahan22, mohazjadoon, rasu, samsai, luish, droucil, allinone123, munnashah, tiyatiwa, sobluecloud, nashbe, kral789, sadiksalad, mintu999, bangladeshbot, p3dheem, steemitmonsters, dieley, dogmasfour, chandu91, antomil, eazz, manfaluthi, gabeman, shamzieyblitz, charismatics, smy, nuklir, astuto, infestor, ohi786, anikpolash, jiashin, vote-psc, hookah, duchess1, rromian, aisteemit, iamthelonewolf, dorik, hasiburrahman, tabraiz.jutt, holabisi, ahmada, theadmiral, netizens, marccage833, vhmcrypto, olegnator, ivrmakers, juma20, budiman01, cindybee, appu6748uooyr, notagain3177, mariaes, clplhepr, animad, hknyasar, ahmedibrahem, gil96ve, amontecal1, omairqazi, jhonniq, mrs.roy, andreeamta, hivaids, hockeygirl21, besikman, airdropcu, dop-dop, platinumsuperman, technicalbero, doctoryak, ajcardib, armuse, kingsteen, kuchee, mrtt, parallel-reality, vaibhavrock, alina2, dogmaportraits, pinkyblogger, heristeem, supeer, isla4, gakk, sintina, jserafael, thecryptoplayer, resteemyourpost, moemyint, abroshan, aralyno, telegramairdrops, kur, koychev22, marybueno, jenellbradley, mista9904, fahmidamti, cryobiosis, jacqueliness, tilenpirih, elgatohuelepega, morrigan, mikersantana1, kuftjs, pasekan, shimukhatun, awww, plumberr, crypt0bear, mashab76, kmitina, shibetrader, steemfuture, adewale123, yonnel, pennijholmes, juliaobando, bacabaca, berniefucksfam, riskaaulia, bulet08, raisha1, gabrielaleiva, withbristy, ankur310794, mosaddekursakib, worlddreams, khobi7, ai2000, chan16735, joseluis0, squidben1, votemachine, sreeram661, starlord28, readrun, bntcamelo, ajose300, aliciazie, eldontang, kaderkhan, eghireme2, jeffersonsalcedo, andresfer0310, meletik, berns, babatunde123, frolik, agaci, danielavrc, saidelbouchri, peter007, totalenigma, nrose1234, daamah, anixon, play24, loliyu, street-girl, charlesmore143, phuoc.hong95, ayman123, atalante, jhsung2002, tubabayrak, sport-is-art, top10ranker, yousuf001, upvoteid, crypto-futurist, bumado, aknirob1, chil, chichu, steem-us, steem-blog247, earthpix, bandmxo88, jerryb, shibah, hg343, speedfast, natmonsalve, samir1993, adigun-anjola, jvhon15, suhana05, speologul, mysteemvote, tirumala, forestplane, jaxxx, herozero, nakita, chemi2712, angelinadivya, hunzlakhan, coffefrees, krommus, iliasjourney, lebey1, sidneychildsh, zazei, thefunnyshit, basant111, cryptobabes, passeggero, mystic074, hrx-07, steemitabuser, cryptopimp, bernietheinbred, doom42, germano, kurieta, efredis, masanam, rosauradels, robow, tids, rozee, dredijinx, mairayasir, kbakadave, onesickplankton, faruqomer, foniz, adx, sefalist, catherinemds, minutiae, sanzib, flawlessal, hobo66, shaiktabassum, shoovoon, protons, renatomacedo, imnotasenuelo, dammyjr, tomalone, smsyfurrahman, t1050108, travelprincess, hadiah, kalilah, haurgeulis, zubzero, jimmyjemsx, justdice, sristeem, programmingtech, mikeok123, masavi, gineo, isosteem, ghulan, cryptoevents, marboe, sabbirkhan, ortnermedia, neljav975, fano, uaksjs, ruzgar3, baycan, balongan, electrobro, daldon, mesafe, afarbomac, meowcliver, slice223, karlpaap, corono, senro888, shapar, shadd, saniul1189, deril, thepharaoh, aritmethos, maixa, yemi90210, ejimevwo, alaminrifat, leandros, sabina10, ajmalkhaan, alfi1212, shoutloud, thestar, iotas, manchupichu, saruman, normad, floass, dynie, daff, kawj, cebuladeals, pollobi, alpha.set, berthatrail, rayhan123, drmax, fantasyman, bmining, nurulsafitri, stevekay, ptkimran, nirjor, transilvaniaman, jannatrina, abuzar1, rizzopablo, kypy24, awais33, abdullah14, hanzala, aliraza83, hammad9, awais34, ahmadkhan1, jaquinz26, diego01798, oscardarma, blogelse, wizzybright, ritkaan, damawan, d0wr0, mozom, sani1189, btrailtrail, kingofdice, guardianofsteem, rijalsaugat75, pampel, kraitahex, tibeo, islandtulip, shanu123, usercrypto46, kroya, fadilah, ayesha221, sw10, widasari, tukdana, badilah, terisi, abcd1, smiths01, muneer1, signin, marielitux, herioswal, adit9, nickibanjlady, ecoman1, hasbydiaz, thachthao, abcd0, henrydatei, a-01, joaquinz26, steemhack, danishmobeen, otrip, zabatar, steempower4, walidjoy, mabruk, nabhan, elfardal, input-user-name, nyo, mctursh, xyphr, salmanrauf, toptrendingnews, bongas, shorelee, ilyassamraoui, xdaniellxx, pgraval, zolindvalp, dontcare, sudi-afrikaan786, wingchun, nwyrk, nirob2, crantar, mohammadsafwan, mytik, untitledvzla, yuli.jpo, deewhy07, aceh-redaksi, waklay, itasteem, tiarasteem, imranpavel, jackers, marko44, a-0-0-0-0-0-a, you-and-me, adnandahal, oliver27, positivehype, endless.drugs, morous70, zulul, jorgebgt, nevlu1, tom-nd-gerry, busy01, ultrapsycho, m1alsan, brave-michael, vibhor-stm01, crypto-maestro, i-m-o, jack-rose, business-man, khusbu, hope-less, adnanghoshal, adnansheye, jaicyjarc, skillarm, a10000, adwas33, yashoda, rsa-vs-ban-team, continue-upvote, rise-with-reason, fernax77, aress, abdullah1143, grey2603, adnanroshan, ddmouse, sgtalienjr, banjo-0, mehedirasel, enfpgirl, niharikalove, amosermama, vicrivasr, meena2009, sidneybrown, dickysaputra, omerbayrak, yiter, dreamthink, valeriaquiaro, nevlu, aaron7, sultana, minatubo, magbilas, gambit.coin, piligrim, flashfiction, used-lessboy, promoteus, ifunanyaikemma, otto11, jayo, hsa61, greenville, a-2-z, andtal, manfred0540, arggil, princeola, felix7d2, neregon, vjmarcus, mabylinne, raqueltaylor, vohon17, imtiaz09, once-upon, herkesegorunmez, ns-team, friday-night, alinabel, mitf, juleskajimenez, a-id, randallstephens, arena10, seasa, hougi, nasso, xom, sigmond, nnu, zuvelt521, dand, littlemaster, huahua, chukieix, testnet, zeld, maria86, cybettex100, ashishdash, darkreunion, aleatory, kshitizraj, ivysrono, jvff, recycle-bin, abakashkhan, funoncamera, kingasf, nacro1000, sockenmollie, gangstars, sofia-legacy, fordmogul, paoladesings, shemi500, calistenia360, tofe, bobbinj, detromix87, zillurrahman, parham26, yevan, indramayu, cantigi, jeffjaxx, quee, plotn, yorneiduvalier, raindropbd, linerus, jamal.mahmud, ippeh, busik, lerass, cryptoknowhow, botje11, leticar5, kshitizrun, homeles-economic, scottandrew201, realawesomeness, bestshamim2020, ephedrin401, faysal111, jvssdrevanth, payi, miladopensador, offended, arslanshn, bnchhetri, superexplorer, losmosqueteros, asunaxzelda, selami321, a7427646, skd40, pporet, burhanahmad, vidio.com, aakashkhan, bipusarker, goodway57, johndnelson, ethelthurston, egon80, bilall, istariray, arceuzz, resteem-bot, silvania, christinelakra, hassanics, windows-7, a-k-nirob, dmnds.southwest3, pepasset, kaulnivna, kazhaval, isseyekayaim, donalddaniel, terrymiller, benniewiggins, maugly, voloshyn, fsherberg, public.library, kdforlife, mrashed043, yan.andy, uzercanan, dgig, bitcoinmining, peterruck, awakenbusiness, mad-karma, xararzx95, precfila, winewinelal, wentertainment, sammu, zickychris, leonelys, hayi, protus88, idiosyncratic1, vjapan, fokir, ashleycarroll, alankeely, jamesjhoffman, kookeret, kazish, itsmikechu, painter3d, rosecat, animefanrd, pentatonix, rebelcrypto, pryde, checo, steemaustin, barrabass123, benadapt, eng.ramy, madyinlay, gameranger, shazikhan, tutoti, randcorp, yul, miniklady, kucukprens, efsane60, dspa, ryanlsmith, crypt0boiler, bigtiddygothgirl, pikar, jakow666, sexbot, kulsego, esteem77, bluznierca, mrakeshrex, tahirmahmood, sillycat, qisyanaura, tech2you, universalglobe, mirkoz, ret, masumalucky, cateyes1990, steemhispano, mankenntihn, adedamola, shahmanabir, saife, marathaking, albertozain22, the-cholo, fargotof, mdomorfaruk9911, bishalacharya, uasteem, mursik, collect1, runen, irosteem, tripx, erpachon, basket.bruntal, fs-pyrotechnik, rahul111, sameershaikh, korshed, adnanshe, satari, sprava, snowmanmedia, sentu1, graeca, jokers, theleastelitist, promoeye, lifequote, humayrakhan, jason482, steemdog, disha2020, akhondo, bumbumear, charity.orphan, thegourmet, stayupdate, anof, sanakhan1920, mhmegh, meedezz, nahin9, jamilhossain, sagar37, gatgat, wasaneagle, johnleon, smartypants, losarang, rambojalil, esbu, mechyz12, mohcinedraou, sukra, igosteem, gnchmurat, eliahsoul, maddieseal, coinsity, shawons, kaoutar, bitcoinmarketss, steemus-bot, carljohnsen, khann001, johjandri, priam, mrsteemian, mridul12, ronibarua, b-01, kadirus94, syedovi, azzuri, sondy, texrex, davidvargas, paparex, civilizedly, ddangerwu, appone, coldfriction, str1k3r, morningcloud, abbasuet5780, futbolsport, everosy, an-account, ruro, sagitariu, james18, demiro86, hasan58475, sallys, khanjh, shivangni, laseemu, horizone, vayukalzh, josephdye, atalgyi, riverlu, noguard, nasau, alftheboss, hdemir, lossbot, tarifhossain757, johnnelson, lakerride, fahrizalarif1995, indertat, aminkhan, steemneworleans, puskas, steemcafe, johnny-appleseed, investfourmore, kaylinart, davidpakman, dana-edwards, lazyman, neutr0nic, theseahorse, spuutim, yadeshina, booster, intellihandling, msowner2, om001,