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

in #steem7 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]))

执行结果如下:

这些与我们在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.13
TRX 0.33
JST 0.034
BTC 110053.56
ETH 4255.01
USDT 1.00
SBD 0.83