create account

Python - Magic Dice Roller 🎲 by aro.steem

View this thread on: hive.blogpeakd.comecency.com
· @aro.steem · (edited)
$8.46
Python - 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

[![Magic-Dice-Google-Chrome-2019-03-24-16-46-44_Trim.gif](https://ipfs.busy.org/ipfs/QmY2MeYeW9wdef5g3jQJvowC1FF1ZxQoJwR459TPoaxTHJ)](https://magic-dice.com/?ref=aro.steem)


#### Requirements
#####   Personal Prerequisite
- **Existing** [STEEM Account](https://www.steemit.com/) 
![](https://cdn.steemitimages.com/DQmbDGEdyn9Fa9cR57EPAvKUtnZVP3tJMrmc7oBhX18ixSb/image.png)
#####   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: ![](https://cdn.steemitimages.com/DQmYGetfkacNcxCyftrR9AqGWU9444UfnzasdkSiggcBPE2/image.png)

* 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'
![](https://cdn.steemitimages.com/DQmR6iKAeyV4nx2e83dECAJTrNCbjwiZ6qV8ahPjFjjmqmG/image.png)
Until you have an empty cell to write your script within:
![](https://cdn.steemitimages.com/DQmbttAp2p6xcqCpzut1mCcDbPpGFPNAA6Jt23V2UW6ihKW/image.png)

* 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
![](https://cdn.steemitimages.com/DQmQc1N8gbm2B6MWJdTgz39hWVfTyJrdLb4pNov6WBFfHMY/image.png)

![](https://cdn.steemitimages.com/DQme62oxVKHpi2xN1yVMCQKvyi3v74wJZnMTK3SSkiciwQ5/image.png)

* Then Wait For An Incoming Transaction Result From Magic Dice:
![](https://cdn.steemitimages.com/DQmRGhhhg3pjF4xTKKaYMKs6Z49Vmw9i3aSaxQZ2yFGQ2yA/image.png)

````
# 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

πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 837 others
properties (23)
authoraro.steem
permlinkpython-magic-dice-roller
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["utopian-io","tutorials","magicdice","busy","python"],"users":["magicdice","aro.steem"],"links":["https://github.com/nnmix/py-magicdice-bot","/@magicdice","https://magic-dice.com/?ref=aro.steem","https://www.steemit.com/","https://jupyter.org/","/@magicdice","https://jupyter.org/try","https://jupyter.org/install.html","https://magic-dice.com/?ref=aro.steem","https://steem.readthedocs.io/en/latest/install.html"],"image":["https://ipfs.busy.org/ipfs/QmY2MeYeW9wdef5g3jQJvowC1FF1ZxQoJwR459TPoaxTHJ","https://cdn.steemitimages.com/DQmbDGEdyn9Fa9cR57EPAvKUtnZVP3tJMrmc7oBhX18ixSb/image.png","https://cdn.steemitimages.com/DQmYGetfkacNcxCyftrR9AqGWU9444UfnzasdkSiggcBPE2/image.png","https://cdn.steemitimages.com/DQmR6iKAeyV4nx2e83dECAJTrNCbjwiZ6qV8ahPjFjjmqmG/image.png","https://cdn.steemitimages.com/DQmbttAp2p6xcqCpzut1mCcDbPpGFPNAA6Jt23V2UW6ihKW/image.png","https://cdn.steemitimages.com/DQmQc1N8gbm2B6MWJdTgz39hWVfTyJrdLb4pNov6WBFfHMY/image.png","https://cdn.steemitimages.com/DQme62oxVKHpi2xN1yVMCQKvyi3v74wJZnMTK3SSkiciwQ5/image.png","https://cdn.steemitimages.com/DQmRGhhhg3pjF4xTKKaYMKs6Z49Vmw9i3aSaxQZ2yFGQ2yA/image.png"]}
created2019-03-24 14:53:57
last_update2019-03-24 14:56:57
depth0
children11
last_payout2019-03-31 14:53:57
cashout_time1969-12-31 23:59:59
total_payout_value6.320 HBD
curator_payout_value2.139 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,250
author_reputation13,589,686,925,958
root_title"Python - Magic Dice Roller 🎲"
beneficiaries
0.
accountbusy.org
weight1,000
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,858,045
net_rshares14,156,789,353,385
author_curate_reward""
vote details (901)
@adewararilwan ·
Nice write up and contribution buddy. I will like to give it try
Good job!
properties (22)
authoradewararilwan
permlinkre-arosteem-python-magic-dice-roller-20190324t162605206z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-03-24 16:26:06
last_update2019-03-24 16:26:06
depth1
children0
last_payout2019-03-31 16:26:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length74
author_reputation5,315,947,909,882
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,863,481
net_rshares0
@cryptoxicate ·
$0.06
awesome, i have been using macros but will give it a try, always want to keep learning
πŸ‘  
properties (23)
authorcryptoxicate
permlinkre-arosteem-python-magic-dice-roller-20190324t150111181z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2019-03-24 15:01:12
last_update2019-03-24 15:01:12
depth1
children2
last_payout2019-03-31 15:01:12
cashout_time1969-12-31 23:59:59
total_payout_value0.043 HBD
curator_payout_value0.014 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length86
author_reputation82,483,397,080,526
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,858,451
net_rshares88,999,790,427
author_curate_reward""
vote details (1)
@aro.steem ·
Yeah i was thinking about an alliance to break the dice, automated with profit sharing, are you a developer?
properties (22)
authoraro.steem
permlinkre-cryptoxicate-re-arosteem-python-magic-dice-roller-20190324t150753118z
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["utopian-io"],"users":[],"links":[],"image":[]}
created2019-03-24 15:07:57
last_update2019-03-24 15:07:57
depth2
children1
last_payout2019-03-31 15:07:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length108
author_reputation13,589,686,925,958
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,858,849
net_rshares0
@cryptoxicate ·
Not a developer, Im IT infrastructure

Posted using [Partiko Android](https://partiko.app/referral/cryptoxicate)
properties (22)
authorcryptoxicate
permlinkcryptoxicate-re-aro-steem-re-cryptoxicate-re-arosteem-python-magic-dice-roller-20190324t202010208z
categoryutopian-io
json_metadata{"app":"partiko","client":"android"}
created2019-03-24 20:20:12
last_update2019-03-24 20:20:12
depth3
children0
last_payout2019-03-31 20:20:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length112
author_reputation82,483,397,080,526
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,872,171
net_rshares0
@intellihandling ·
Dear @aro-steem, but when i modified this file with my own rules, what i should do with it to make it running on chrome browser?
properties (22)
authorintellihandling
permlinkre-arosteem-python-magic-dice-roller-20190326t053127723z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["aro-steem"],"app":"steemit/0.1"}
created2019-03-26 05:31:27
last_update2019-03-26 05:31:27
depth1
children0
last_payout2019-04-02 05:31:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length128
author_reputation19,898,926,679,839
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,963,860
net_rshares0
@msowner2 ·
nice ! you can try script with us too =)


---
πŸš€ πŸŒ•

Moon your steem everyday ! Instant Dividend payout after every game. chance to **WIN 235,318 steemies** every round. Participate in Players Upvote round (every 144 mins) worth $0.75
 <a href="http://bit.ly/moonSTEEM">moonSTEEM.com</a>
properties (22)
authormsowner2
permlinkre-arosteem-python-magic-dice-roller-20190326t103645300z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steempeak/1.9.3"}
created2019-03-26 10:36:48
last_update2019-03-26 10:36:48
depth1
children0
last_payout2019-04-02 10:36:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length286
author_reputation264,549,673,006
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,977,457
net_rshares0
@portugalcoin ·
$10.18
Thank you for your contribution @aro.steem.
After reviewing your tutorial we suggest the following points listed below:

- The structure of your tutorials is a bit confusing. See other tutorials that are placed in utopian to see how they structure the tutorials.

- We suggest you explain in more detail all the steps that you describe in your tutorial.

- Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

- We suggest that in your next contribution put a title with more key words about what you will explain in the tutorial.

Thank you for your work in developing this tutorial.
Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/3-3-3-4-2-3-4-3-).

---- 
Need help? Chat with us on [Discord](https://discord.gg/uTyJkNm).

[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , , , , , , ,
properties (23)
authorportugalcoin
permlinkre-arosteem-python-magic-dice-roller-20190324t154201961z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"users":["aro.steem"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/3-3-3-4-2-3-4-3-","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2019-03-24 15:42:03
last_update2019-03-24 15:42:03
depth1
children2
last_payout2019-03-31 15:42:03
cashout_time1969-12-31 23:59:59
total_payout_value7.748 HBD
curator_payout_value2.435 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,136
author_reputation603,431,202,521,855
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,860,882
net_rshares15,637,495,601,862
author_curate_reward""
vote details (19)
@aro.steem · (edited)
Thank you, if this is a developer / coding tutorial is there another tag to use? It will be better for developers to understand than other users.
properties (22)
authoraro.steem
permlinkre-portugalcoin-re-arosteem-python-magic-dice-roller-20190324t154516670z
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.6","format":"markdown","tags":["utopian-io"],"users":[],"links":[],"image":[]}
created2019-03-24 15:45:18
last_update2019-03-24 17:16:27
depth2
children0
last_payout2019-03-31 15:45:18
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length145
author_reputation13,589,686,925,958
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,861,053
net_rshares0
@utopian-io ·
Thank you for your review, @portugalcoin! Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-arosteem-python-magic-dice-roller-20190324t154201961z-20190327t014134z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-27 01:41:36
last_update2019-03-27 01:41:36
depth2
children0
last_payout2019-04-03 01:41:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length64
author_reputation152,955,367,999,756
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,014,859
net_rshares0
@steem-ua ·
#### Hi @aro.steem!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-python-magic-dice-roller-20190324t175638z
categoryutopian-io
json_metadata"{"app": "beem/0.20.19"}"
created2019-03-24 17:56:39
last_update2019-03-24 17:56:39
depth1
children0
last_payout2019-03-31 17:56:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length288
author_reputation23,214,230,978,060
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,867,349
net_rshares0
@utopian-io ·
Hey, @aro.steem!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-python-magic-dice-roller-20190325t060648z
categoryutopian-io
json_metadata"{"app": "beem/0.20.17"}"
created2019-03-25 06:06:48
last_update2019-03-25 06:06:48
depth1
children0
last_payout2019-04-01 06:06:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length591
author_reputation152,955,367,999,756
root_title"Python - Magic Dice Roller 🎲"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,895,962
net_rshares0