第一个steem程序,备份你的steem文章!

in #steem6 years ago

steem)相见恨(狠投)晚(一万)文章中说过,买了1万RMB的steem power,而且比较看好steem的发展,但这毕竟是感性认识,只是因为steem是起步比较早的区块链内容激励社区,起跑线上有优势!

为了更多的了解steem,在有时间研究它的代码之前,先看看它的开发文档吧!


steem开发者官网
https://developers.steem.io/

开发库

JavaScript

https://github.com/steemit/steem-js

Python

http://steem.readthedocs.io/en/latest/

有我个人比较喜欢的python库,后面基本上会先从python开始啦

第三方库

Ruby Client

steemSQL

MongoDB

SteemDevs Chat

Python安装

(env3) localhost:steem Chaim$ pip install steem
(env3) localhost:steem Chaim$ pip install -U steem

需要python3以上版本,用virtualenv比较方便

记得是steem,我经常习惯性的打成游戏的steam,主要是steam这个库也有,然后用不了:-()

第一个steem程序

安装好了试一下,看能不能用,建立steem_test.py文件,如下:

from steem import Steem

s = Steem()
d = s.get_account("chaimyu")
for k in d:
    print(k + ":" + str(d[k]))

执行结果如下:

(env3) localhost:steem Chaim$ python steem_test.py 
id:775653
name:chaimyu
owner:{'weight_threshold': 1, 'account_auths': [], 'key_auths': [['STM5kUGrPszxRG6d2mkTpnUerHNF1FCyXivSt1mmeCjZN2q65P5bB', 1]]}
active:{'weight_threshold': 1, 'account_auths': [], 'key_auths': [['STM5qUabAi7PX9m3vYSDQEgi3j1n1uqNWmj7uhK6Qcy7aE3b8VhhS', 1]]}
posting:{'weight_threshold': 1, 'account_auths': [], 'key_auths': [['STM4yPgNQ2JckGVf9WVjstD9g2RychNhrQKrwRFnM69RsKBBWrDkd', 1]]}
memo_key:STM7K9pBtcEuGjKCk5qC8EkoSbiyU7md2cvkJajfkZqL2z58pm85V
json_metadata:{"profile":{"name":"flyingfish","about":"One day sitting in the well looked at the sky, blowing the wind uphole, jumping out of the well, dancing in the wind!","profile_image":"https://steemitimages.com/DQmbqJQ8Cow3cQq2HUXdap69NXQedBwg9reAed8cmxwinb7/D4F1EE77-CBDA-4E36-BA6C-05755C20DE43.jpeg","cover_image":"https://steemitimages.com/DQmXST6kvE2JxpFF7ke2S5qjkcRk8NAyxux1JTEHnekvJRk/1C682E30-127B-4FD5-84EC-51F9BB5CC3EB.jpeg","location":"China","website":"https://steemit.com/@chaimyu"}}
proxy:
last_owner_update:1970-01-01T00:00:00
last_account_update:2018-03-12T04:07:57
created:2018-02-26T03:44:30
mined:False
recovery_account:steem
last_account_recovery:1970-01-01T00:00:00
reset_account:null
comment_count:0
lifetime_vote_count:0
post_count:95
can_vote:True
voting_power:9800
last_vote_time:2018-03-26T07:50:39
balance:0.000 STEEM
savings_balance:0.000 STEEM
sbd_balance:0.000 SBD
sbd_seconds:0
sbd_seconds_last_update:1970-01-01T00:00:00
sbd_last_interest_payment:1970-01-01T00:00:00
savings_sbd_balance:0.000 SBD
savings_sbd_seconds:0
savings_sbd_seconds_last_update:1970-01-01T00:00:00
savings_sbd_last_interest_payment:1970-01-01T00:00:00
savings_withdraw_requests:0
reward_sbd_balance:1.143 SBD
reward_steem_balance:0.007 STEEM
reward_vesting_balance:1022.622727 VESTS
reward_vesting_steem:0.501 STEEM
vesting_shares:1693801.851566 VESTS
delegated_vesting_shares:0.000000 VESTS
received_vesting_shares:0.000000 VESTS
vesting_withdraw_rate:0.000000 VESTS
next_vesting_withdrawal:1969-12-31T23:59:59
withdrawn:0
to_withdraw:0
withdraw_routes:0
curation_rewards:24
posting_rewards:947
proxied_vsf_votes:[0, 0, 0, 0]
witnesses_voted_for:3
last_post:2018-03-26T07:50:39
last_root_post:2018-03-26T07:50:39
average_bandwidth:40508842622
lifetime_bandwidth:470450000000
last_bandwidth_update:2018-03-26T07:50:39
average_market_bandwidth:1250000000
lifetime_market_bandwidth:1250000000
last_market_bandwidth_update:2018-03-19T14:22:18
vesting_balance:0.000 STEEM
reputation:14504760577
transfer_history:[]
market_history:[]
post_history:[]
vote_history:[]
other_history:[]
witness_votes:['ety001', 'justyy', 'skenan']
tags_usage:[]
guest_bloggers:[]

这些与我们在steemd.com看到的数据是一样的。

有个小发现,就是用户的图片和背景图片,可以直接拷贝profile中的profile_image和cover_image的url,在浏览器中打开就能看到全图了!例如 @sweetsssj美女背景图,名人和美女总是避免不了被最先关照的,应该不会介意吧!

对于一些python库没实现的方法,也可以直接调用,如下:

s = Steem()

# this call
s.get_followers('furion', 'abit', 'blog', 10)

# is same as
s.exec('get_followers',
       'furion', 'abit', 'blog', 10,
        api='follow_api')

怎么取发表的文章

初次有这个想法是发现以前发的贴子不能编辑了,可是有很多没有保留原始md文件,后来在看一些贴子时发现其他朋友也有这个想法,看起来实现也很简单,刚好有时间就试一下。

api中找到一个取blog的接口:

get_blog(account: str, entry_id: int, limit: int)

调用这个api试一下:

(env3) localhost:steem Chaim$ python getsteemblog.py 
[{'comment': {'id': 40583732, 'author': 'chaimyu', 'permlink': '3a2vxy', 'category': 'ethereum', 'parent_author': '', 'parent_permlink': 'ethereum', 'title': '以太坊实战【地址监控四】', 'body': '![](https://steemitimages.com/DQmTHbFrZNTSJtrCQQzFoqh9LUThnjFDGkVsR37cz5fZ7P8/image

返回的是一个json格式的列表,在python里面已经是dict了,其中title、body就是我们需要的内容,这样要读取自己的文章就很简单了!

但是这个entry_id没有文档说明,多次试了下,发现是这样的:entry_id指定从第几篇开始往前读limit篇文章,如果entry_id=1,limit指定多少最多也只有第2篇和第1篇文章(此处注意下很多程序计数都是从0开始的),如果entry_id=2开始那就是最多读三篇文章,特殊的是如果entry_id=0或者负数则是从最新的文章开始读取。

#coding=utf8

import os

from steem import Steem

def getsteemblog(account, entry_id, limit):
    s = Steem()
    blogs = s.get_blog(account, entry_id, limit)

    strSubDir = account
    try:
        os.mkdir(strSubDir)
    except Exception as e:
        pass

    for b in blogs:
        strTitle = b["comment"]["title"].replace("/", "_")
        strFile = strSubDir + "/" + strTitle + ".md"
        print(strFile)
        file = open(strFile, 'w')
        file.write(b["comment"]["body"])
        file.close()

if __name__ == '__main__':
    import sys
    import getopt

    usagemsg = '''\
    usage:getsteemblog [-a steemaccount] [-l]

    Where:
    --account steemaccount
    -a steemaccount

    -limit
    -l
        Reading the number of blogs from the latest.
    '''

    def usage(code, msg=None):
        if msg:
            print(msg)
        print(usagemsg)
        sys.exit(code)

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'a:l:', ['account=', 'limit='])
    except getopt.error as msg:
        usage(1, msg)

    if args:
        usage(1, 'Too many arguments')

    strAccount = None
    nLimit = 500
    for opt, arg in opts:
        if opt in ('-a', '--account'):
            strAccount = arg
        elif opt in ('-l', '--limit'):
            nLimit = int(arg)

    if strAccount is None:
        usage(1)

    getsteemblog(strAccount, 0, nLimit)

以上是完整的程序,会在执行程序目录建立以steemaccount为名称的子目录,读到的文章原始内容会放在子目录下,自己用来做steem内容的备份已经足够了,当然你也可以取一些好作者的文章在本地查看。

这是用我的Steem用户名执行的结果,最近的文章都保存下来了!

(env3) localhost:steem Chaim$ python getsteemblog.py -a chaimyu
chaimyu/以太坊实战【地址监控四】.md
chaimyu/以太坊实战【地址监控三】.md
chaimyu/(steem)相见恨(狠投)晚(一万).md
chaimyu/以太坊实战【地址监控二】.md
chaimyu/以太坊常用客户端简介.md
chaimyu/以太坊实战【地址监控一】.md
chaimyu/骗炮行情,小仓位开始建仓.md
chaimyu/区块链技术中的石墨烯是什么.md
chaimyu/量化交易研究系列【交易所分析】.md
chaimyu/看9000左右能不能支撑住.md
chaimyu/ERC20代币传输给合约地址可能会丢失.md
chaimyu/试图猜一下币世界的谜语.md
chaimyu/steemit bindwidth limit exceeded原因和解决方法.md
chaimyu/比特币研究系列【白皮书】.md
chaimyu/区域链研究系列【技术术语】.md
chaimyu/区块链玩猫笔记.md
chaimyu/区块链研究系列【数字代币】.md
chaimyu/NEO研究系列【基本信息和安装】.md
chaimyu/作者简介.md
chaimyu/快速使用ShapeShift转换虚拟币.md
chaimyu/区块链研究系列【ICO】.md
chaimyu/以太坊研究系列【代币发行】.md
chaimyu/以太坊研究系列【合约进阶】.md
chaimyu/以太坊研究系列【智能合约】.md
chaimyu/以太坊研究系列【web3交互】.md
chaimyu/以太坊研究系列【Mist】.md
chaimyu/以太坊研究系列【基本信息】.md
chaimyu/以太坊研究系列【geth客户端调用mist部署的智能合约】.md
chaimyu/以太坊研究系列【私链搭建、挖矿、交易】.md
chaimyu/Electrum研究系列【代码结构和助记词生成】.md
chaimyu/After the article is deleted, the picture is still there?.md
chaimyu/brew如何安装指定版本软件.md
chaimyu/Mac下pip install Permission denied解决方法.md
chaimyu/Mac下brew install & link permission denied解决方法.md
chaimyu/steemit如何最方便的设置头像和封面图片?.md
chaimyu/Electrum研究系列【安装】.md
chaimyu/steemit.com vs cnsteem.com @skenan.md
chaimyu/Ethereum Research【message protocol】.md

谁知道有没有能方便发布文章到多个内容平台的软件吗?例如简书、博客、steem等


感谢您阅读 @chaimyu 的帖子,期待您能留言交流!

Sort:  

Lotto from @minnowfollower | Upvote the post for a chance win from ALL the SBD post rewards.

我昨天刚安装好了steem-python,做了一些测试。你的帖子来的及时!

多交流,steem可以聊天吗?

有个steem chat,但是没有用过。

好,我加你~

Congrats! This post was resteemed and upvoted by @postresteem!

Send 0.500 SBD or 0.500 STEEM to @postresteem with your post URL in the memo. Get your post resteemed to 7000+ followers and get a minimum of 25+ upvotes!

Want to learn more? Click here!

Coin Marketplace

STEEM 0.17
TRX 0.14
JST 0.028
BTC 58097.21
ETH 2581.79
USDT 1.00
SBD 2.41