create account

python开发steem机器人,通过json文件管理beempy创建的steem账号密码 by dappcoder

View this thread on: hive.blogpeakd.comecency.com
· @dappcoder · (edited)
$4.42
python开发steem机器人,通过json文件管理beempy创建的steem账号密码
steem使用的是分级授权,因此一个steem账号,具有4个密码:"owner", "active", "posting", "memo".

这些密码都很长,靠人脑记住,是不太现实.只能靠文件存储,让机器人自己读写.

上次已经示范了如何通过beempy,现在就让这个创建过程使用json文件管理.

![beem.png](https://cdn.steemitimages.com/DQmYi9HNRfvLGpneXnQsY9DjKNpChaNC7P6tNK1L1DJqpBv/beem.png)

json文件存储的格式(/bots.json):
```json
{
    "nodes": [
        "https://anyx.io",
        "https://api.steemit.com"
    ],
    "steems": {
        "steemaccount": {
        }
    }
}
```

这里就示范beempy创建新号存入json文件(create_claimed_account_beem.py):
--------------------------------------
```python
#!/usr/bin/python
# -*- coding: UTF-8 -*-

# 用消耗RC领取的pending claimed accounts,创建 steem 新号
# Export the key of the specified account from the local Wallet
# python create_claimed_account_beem.py creator account

import sys
import getopt
import time
import json
# from beem import Steem
from beem.account import Account
from beem.instance import shared_steem_instance
from beemgraphenebase.account import BrainKey, PasswordKey

# 必须有创建者 creator 和新号 account
try:
    creator = sys.argv[1]
    account = sys.argv[2]
except Exception as e:
    sys.exit()
print('creator:', creator)
print('account:', account)

stm = shared_steem_instance()
# 解锁本地钱包(操作钱包时,需要解锁,否则不用)
# 输入本地钱包密码或在代码中直接赋值
# Enter the local wallet password or set value directly in the code
password = ''  # 'walletkey'
if not password:
    password = input('local wallet password : ')
stm.wallet.unlock(password)

# 本地存储 steem 账号信息的文件
accounts_file = '/bots.json'

try:
    # 创建者账号
    creatorA = Account(creator, steem_instance=stm)
    accountA = Account(account, steem_instance=stm)
except Exception as e:
    print('account can be created:', account)

# 生成一套新密码
bk = BrainKey()
brainkey = bk.get_brainkey()
print('brain key:', str(brainkey))
prikey = str(bk.get_private())
print('private key:', str(prikey))
pubkey = format(bk.get_public(), "STM")
print('public key:', str(pubkey))

# 创建新号:本地存储 owner(默认不存储)
tx = stm.create_claimed_account(
    account, creator=creatorA, password=prikey, store_owner_key=True)
print('create_claimed_account:', json.dumps(tx, indent=4))

# 获取整套密钥
posting_key = PasswordKey(account, prikey, role="posting", prefix=stm.prefix)
active_key = PasswordKey(account, prikey, role="active", prefix=stm.prefix)
memo_key = PasswordKey(account, prikey, role="memo", prefix=stm.prefix)
owner_key = PasswordKey(account, prikey, role="owner", prefix=stm.prefix)
# 提取整套密钥中的公钥
# active_pubkey = active_key.get_public_key()
# owner_pubkey = owner_key.get_public_key()
# posting_pubkey = posting_key.get_public_key()
memo_pubkey = memo_key.get_public_key()
# 提取整套密钥中的私钥
active_privkey = active_key.get_private_key()
posting_privkey = posting_key.get_private_key()
owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()

print('posting_privkey:', str(posting_privkey))
print('active_privkey:', str(active_privkey))
print('owner_privkey:', str(owner_privkey))
print('memo_privkey:', str(memo_privkey))

with open(accounts_file, 'r', encoding='utf-8') as f:
    # 直接用load()传入文件对象,将文件中字符串内容转为json字典
    accounts_dict = json.load(f)
    # print('old.accounts_dict:', accounts_dict)
    accounts_dict['steems'][account] = {
        "name": account,  # steem 账号名称
        "email": "sample@,pwd",  # steem 注册 email
        "mobile": "sample9,from",  # steem 注册 手机号
        "keys": {
            "brain": brainkey,  # steem 账号的脑密码
            "private": prikey,  # steem 账号当前的私钥
            "public": pubkey,  # steem 账号当前的公钥
            "history": [   # steem 账号的私钥的修改记录
                prikey,
                "sample2",
                "sample3"
            ],
            "posting": str(posting_privkey),  # steem 账号的 posting 私钥
            "active": str(active_privkey),  # steem 账号的 active 私钥
            "owner": str(owner_privkey),  # steem 账号的 owner 私钥
            "memo": str(memo_privkey),  # steem 账号的 memo 私钥,用于解密memo
            "memo_key": str(memo_pubkey)  # steem 账号的 memo 公钥,用于加密memo
        }
    }
with open(accounts_file, 'w', encoding='utf-8') as f:
    # 用dump()传入字典和文件对象,将json字典转为字符串,存入文件
    json.dump(accounts_dict, f, indent=4, ensure_ascii=False)

```
执行程序:`python create_claimed_account_beem dappcoder newaccddd`
执行结果,和预期一致:
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 103 others
properties (23)
authordappcoder
permlinkpython-steem-json-beempy-steem
categoryhive-180932
json_metadata{"tags":["cn","hive-143316","cn-reader","cn-curation","sct","sct-cn","sct-freeboard","palnet","upfundme","zzan","jjm","mediaofficials","lassecash","liv","steemleo","busy","esteem","esteem-cn","cn-stem","steemstem","cn-programming","dblog","marlians","neoxian","actnearn"],"app":"busy/2.5.4","format":"markdown","community":"esteemapp","image":"https://cdn.steemitimages.com/DQmYi9HNRfvLGpneXnQsY9DjKNpChaNC7P6tNK1L1DJqpBv/beem.png"}
created2020-02-18 06:51:45
last_update2020-02-23 03:00:00
depth0
children3
last_payout2020-02-25 06:51:45
cashout_time1969-12-31 23:59:59
total_payout_value2.200 HBD
curator_payout_value2.224 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,194
author_reputation9,480,331,507,174
root_titlepython开发steem机器人,通过json文件管理beempy创建的steem账号密码
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,566,965
net_rshares15,583,404,153,982
author_curate_reward""
vote details (167)
@esteemapp ·
**Yay!** <br>Your post has been **boosted with ESTM**. Keep up the good work! <br>Dear reader, Install [Android](https://play.google.com/store/apps/details?id=app.esteem.mobile.android), [iOS](https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=1451896376&mt=8) Mobile app or [Windows, Mac, Linux](https://github.com/esteemapp/esteem-surfer/releases) Surfer app!<br>Learn more: https://esteem.app <br>Join our discord: https://discord.me/esteem
properties (22)
authoresteemapp
permlinkre-2020221t195929959z
categoryhive-180932
json_metadata{"tags":["esteem"],"app":"esteem/2.2.2-welcome","format":"markdown+html","community":"esteem.app"}
created2020-02-21 18:59:30
last_update2020-02-21 18:59:30
depth1
children0
last_payout2020-02-28 18:59:30
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_length459
author_reputation420,443,679,514,793
root_titlepython开发steem机器人,通过json文件管理beempy创建的steem账号密码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,689,161
net_rshares0
@marcos-708 ·
### According to the Bible, *Bro. Eli Soriano: What really happened to Joseph Smith?*
### Watch the Video below to know the Answer...
***(Sorry for sending this comment. We are not looking for our self profit, our intentions is to preach the words of God in any means possible.)***
https://youtu.be/83nsg2zU5_4
Comment what you understand of our Youtube Video to receive our full votes. We have 30,000 #SteemPower. It's our little way to **Thank you, our beloved friend.**  
Check our [Discord Chat](https://discord.gg/vzHFNd6) 
Join our Official Community: https://steemit.com/created/hive-182074
👍  
👎  
properties (23)
authormarcos-708
permlink7mqti74dt23
categoryhive-180932
json_metadata""
created2020-02-23 03:08:18
last_update2020-02-23 03:08:18
depth1
children0
last_payout2020-03-01 03:08: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_length599
author_reputation-7,490,395,056,362
root_titlepython开发steem机器人,通过json文件管理beempy创建的steem账号密码
beneficiaries[]
max_accepted_payout10,000.000 HBD
percent_hbd100
post_id95,730,168
net_rshares-25,311,134,220
author_curate_reward""
vote details (2)
@steemitboard ·
Congratulations @dappcoder! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://steemitimages.com/60x70/http://steemitboard.com/@dappcoder/posts.png?202002180745"></td><td>You published more than 30 posts. Your next target is to reach 40 posts.</td></tr>
</table>

<sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@dappcoder) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=dappcoder)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Do not miss the last post from @steemitboard:**
<table><tr><td><a href="https://steemit.com/steemitboard/@steemitboard/valentine-s-day-challenge-give-a-badge-to-your-beloved"><img src="https://steemitimages.com/64x128/http://i.cubeupload.com/LvDzr5.png"></a></td><td><a href="https://steemit.com/steemitboard/@steemitboard/valentine-s-day-challenge-give-a-badge-to-your-beloved">Valentine's day challenge - Give a badge to your beloved!</a></td></tr></table>

###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-dappcoder-20200218t081344000z
categoryhive-180932
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2020-02-18 08:13:42
last_update2020-02-18 08:13:42
depth1
children0
last_payout2020-02-25 08:13:42
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_length1,353
author_reputation38,975,615,169,260
root_titlepython开发steem机器人,通过json文件管理beempy创建的steem账号密码
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,568,642
net_rshares0