Primas-api文档学习笔记(2)——查询文章列表

in cn •  6 years ago 

img

在上一节,Primas-api文档学习笔记(1)中,我们学习了一下基本的查询账号操作。

现在我们来学习更多的查询操作,这次的目标是查询自己的所有文章,并弄一个列表出来。

文章列表
https://rigel-a.primas.network/v3/accounts/账户ID/content

这是查询用户文章列表的API,只要把账户ID写进去就能查询了。账户ID上一节有说怎么查询。

https://rigel-a.primas.network/v3/accounts/0cb5c16d22c04388ea5917cfc7af57f5baa8ff2c01ea81d3f32d4bd8984d2d15/content

这是我自己的,打进浏览器后,就能查看了,非常多的信息,稍微有点乱。我们可以用JSON解释器来弄整齐一点。

img

这里有很多文章信息,包括标题,作者,简介,链接等等。我们用python写一个小程序,把这些信息归档。

上源代码:

# coding: utf-8
import requests
import json

r = requests.get("https://rigel-a.primas.network/v3/accounts/0cb5c16d22c04388ea5917cfc7af57f5baa8ff2c01ea81d3f32d4bd8984d2d15/content")
r.json=r.json()
p=1
id=0
try:
    while p==1:
        title2 = r.json["data"][id]
        title = r.json["data"][id]["title"]
        name = r.json["data"][id]["creator"]["account_name"]
        dna = r.json["data"][id]["dna"]
        url="https://cn.primas.io/article/%s" % dna

        print("---------------------------------------------------------------------------------------------------------------")
        print("序号:",id+1)
        print("标题:",title)
        print("作者:",name)
        print("链接:",url)
        print("DNA:",dna)
        print("---------------------------------------------------------------------------------------------------------------")
        id += 1
except:
    print("结束")

结果是:

---------------------------------------------------------------------------------------------------------------
序号: 1
标题: Primas-api文档学习笔记(1)
作者: 卖鱼的
链接: https://cn.primas.io/article/2FTB7ZBYAUSYL1A54NJNF8M86JM45LU00NRXRN7OR8R4Z86AH4
DNA: 2FTB7ZBYAUSYL1A54NJNF8M86JM45LU00NRXRN7OR8R4Z86AH4
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 2
标题: 作为一个宝宝,我非常的忙碌,忙的快没时间玩了
作者: 卖鱼的
链接: https://cn.primas.io/article/3VBQGXJVQATX85R7JHM6BZYA08NZCBJAKLGJ6DK2DKUJKYWQHY
DNA: 3VBQGXJVQATX85R7JHM6BZYA08NZCBJAKLGJ6DK2DKUJKYWQHY
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 3
标题: 神秘的API到底是什么?
作者: 卖鱼的
链接: https://cn.primas.io/article/4CWI3H3FVZ7FLC1E4VND9JWUJKYZTPAUJ3D3SIA9H907MHHM0I
DNA: 4CWI3H3FVZ7FLC1E4VND9JWUJKYZTPAUJ3D3SIA9H907MHHM0I
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 4
标题: Primas重新起航,积极支持优秀作者!
作者: 卖鱼的
链接: https://cn.primas.io/article/26GYHAC7ARCFUIU9EW3UA9DP0LLR1OOVJJY8VR8HZIYDR0EK7Q
DNA: 26GYHAC7ARCFUIU9EW3UA9DP0LLR1OOVJJY8VR8HZIYDR0EK7Q
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 5
标题: Primas重新起航,努力支持优秀作者!
作者: 卖鱼的
链接: https://cn.primas.io/article/3IE2IWEOFFX7OOOKJ9C694LERUXXDT46R7GA32HNXETXHV5D52
DNA: 3IE2IWEOFFX7OOOKJ9C694LERUXXDT46R7GA32HNXETXHV5D52
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 6
标题: 复杂度陷阱
作者: 卖鱼的
链接: https://cn.primas.io/article/3LY5COSAAXX6NPGIR54MUZIFAKENICX1T45ZMKMH6YU8OU0NLR
DNA: 3LY5COSAAXX6NPGIR54MUZIFAKENICX1T45ZMKMH6YU8OU0NLR
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 7
标题: Primas将再次扬帆起航
作者: 卖鱼的
链接: https://cn.primas.io/article/2KBUC821HX45KVIUJ4ALE8PEREFIRU3WRSXSBT9C5DOFLOZZDK
DNA: 2KBUC821HX45KVIUJ4ALE8PEREFIRU3WRSXSBT9C5DOFLOZZDK
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 8
标题: PRIMAS(奇点),投资价值如何,值得长期持有么?
作者: 卖鱼的
链接: https://cn.primas.io/article/5801A8M8RYV5PYO6XGUK6ZI1KO0JGUDIPOVWGO8SZ9WRPLXO5W
DNA: 5801A8M8RYV5PYO6XGUK6ZI1KO0JGUDIPOVWGO8SZ9WRPLXO5W
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 9
标题: 偶尔画个画系列:生活需要爱与笑容
作者: 卖鱼的
链接: https://cn.primas.io/article/J52M8BJ9829OA04T3LG8AJS6Y8RJY184DG1J1XMTIXRK9JRJ8
DNA: J52M8BJ9829OA04T3LG8AJS6Y8RJY184DG1J1XMTIXRK9JRJ8
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 10
标题: 煎饼果子和杂粮煎饼的争吵
作者: 卖鱼的
链接: https://cn.primas.io/article/3PGNWFAXAW851SPAWR4F9PJDQ1TLVAY9X1S4RLXMO3XQ2AXE2L
DNA: 3PGNWFAXAW851SPAWR4F9PJDQ1TLVAY9X1S4RLXMO3XQ2AXE2L
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 11
标题: 小圆圆与梦之世界(45)师徒
作者: 卖鱼的
链接: https://cn.primas.io/article/1RORG0RS5B9LA4ZONTQ1DRGD7NT54J82TGV5MHML00X5957QU8
DNA: 1RORG0RS5B9LA4ZONTQ1DRGD7NT54J82TGV5MHML00X5957QU8
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 12
标题: 小圆圆与梦之世界(33)对决!火龙!
作者: 卖鱼的
链接: https://cn.primas.io/article/5RNCJ2A0VA5205ZEQMOO763T28I1KO0QX0PAOLE9YLX68PSRY0
DNA: 5RNCJ2A0VA5205ZEQMOO763T28I1KO0QX0PAOLE9YLX68PSRY0
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 13
标题: 小圆圆与梦之世界(19)梦
作者: 卖鱼的
链接: https://cn.primas.io/article/41AE8SHZNCUQPCHG6WWH4AWNM6IA5AQESI72FQRVKVHNCNJ28Q
DNA: 41AE8SHZNCUQPCHG6WWH4AWNM6IA5AQESI72FQRVKVHNCNJ28Q
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
序号: 14
标题: 【扶贫计划】莫名扶了几个富翁
作者: 卖鱼的
链接: https://cn.primas.io/article/60QKJD1E8AF49P14PSLUZZ19YOZ69VRE2SXPXNC2Q7XUIXP2MD
DNA: 60QKJD1E8AF49P14PSLUZZ19YOZ69VRE2SXPXNC2Q7XUIXP2MD
---------------------------------------------------------------------------------------------------------------
结束

很好的把我的文章信息全部列出来了。这样就很方便我们做一些归档操作。大家学会了吗?快动起手来学习吧。

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!