办公问答网

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 98|回复: 0

Pyzotero | zotero api python 实现

[复制链接]

3

主题

5

帖子

10

积分

新手上路

Rank: 1

积分
10
发表于 2023-4-10 08:46:25 | 显示全部楼层 |阅读模式
Zotero是一款开源的文献管理软件,通过浏览器插件Zotero Connector可以便捷的将文献导入文献库中。同时可以选择将文献信息保存至 Zotero 在线库中。
特别的,pyzotero 实现了对 zotero 网站 api 的封装,可以用来获取文献信息。
对其进行部分使用演示如下
全局信息
>>> from pyzotero import zotero

# 实例化
>>> zot = zotero.Zotero(library_id, library_type, api_key, locale='zh-CN')

# 查看当前 实例 的相关信息和访问权限
>>> zot.key_info()
{'key': 'your api_key', 'userID': your userid, 'username': 'your username', 'displayName': '', 'access': {'user': {'library': True, 'files': True, 'notes': True}}}

# 所有可用的 条目 类型
>>> zot.item_types()
[{'itemType': 'email', 'localized': 'E-mail'}, {'itemType': 'patent', 'localized': '专利'}, {'itemType': 'book', 'localized': '书籍'}, {'itemType': 'conferencePaper', 'localized': '会议论文'}, {'itemType': 'letter', 'localized': '信件'}, {'itemType': 'blogPost', 'localized': '博客帖子'}, {'itemType': 'instantMessage', 'localized': '即时讯息'}, {'itemType': 'case', 'localized': '司法案例'}, {'itemType': 'hearing', 'localized': '听证会'}, {'itemType': 'bookSection', 'localized': '图书章节'}, {'itemType': 'map', 'localized': '地图'}, {'itemType': 'thesis', 'localized': '学位论文'}, {'itemType': 'manuscript', 'localized': '手稿'}, {'itemType': 'report', 'localized': '报告'}, {'itemType': 'newspaperArticle', 'localized': '报纸文章'}, {'itemType': 'podcast', 'localized': '播客'}, {'itemType': 'document', 'localized': '文档'}, {'itemType': 'journalArticle', 'localized': '期刊文章'}, {'itemType': 'magazineArticle', 'localized': '杂志文章'}, {'itemType': 'bill', 'localized': '法案'}, {'itemType': 'statute', 'localized': '法规'}, {'itemType': 'presentation', 'localized': '演示文档'}, {'itemType': 'radioBroadcast', 'localized': '电台广播'}, {'itemType': 'film', 'localized': '电影'}, {'itemType': 'tvBroadcast', 'localized': '电视广播'}, {'itemType': 'encyclopediaArticle', 'localized': '百科全书文章'}, {'itemType': 'note', 'localized': '笔记'}, {'itemType': 'webpage', 'localized': '网页'}, {'itemType': 'artwork', 'localized': '艺术品'}, {'itemType': 'videoRecording', 'localized': '视频'}, {'itemType': 'forumPost', 'localized': '论坛帖子'}, {'itemType': 'dictionaryEntry', 'localized': '词条'}, {'itemType': 'computerProgram', 'localized': '软件'}, {'itemType': 'interview', 'localized': '采访稿'}, {'itemType': 'audioRecording', 'localized': '音频'}, {'itemType': 'preprint', 'localized': '预印本'}]

# 所有 条目 字段
>>> zot.item_fields()
[{'field': 'DOI', 'localized': 'DOI'}, {'field': 'ISBN', 'localized': 'ISBN'}, {'field': 'ISSN', 'localized': 'ISSN'}, {'field': 'url', 'localized': 'URL'}, {'field': 'patentNumber', 'localized': '专利号'}, {'field': 'subject', 'localized': '主题'}, {'field': 'bookTitle', 'localized': '书名'}, {'field': 'repository', 'localized': '仓库'}, {'field': 'priorityNumbers', 'localized': '优先申请号'}, {'field': 'session', 'localized': '会期'}, {'field': 'conferenceName', 'localized': '会议名称'}, {'field': 'meetingName', 'localized': '会议名称'}, {'field': 'proceedingsTitle', 'localized': '会议论文集标题'}, {'field': 'letterType', 'localized': '信件类型'}, {'field': 'company', 'localized': '公司'}, {'field': 'issueDate', 'localized': '公告日期'}, {'field': 'publicLawNumber', 'localized': '公法号'}, {'field': 'extra', 'localized': '其它'}, {'field': 'publisher', 'localized': '出版社'}, {'field': 'distributor', 'localized': '分发者'}, {'field': 'journalAbbreviation', 'localized': '刊名缩写'}, {'field': 'blogTitle', 'localized': '博客标题'}, {'field': 'volume', 'localized': '卷次'}, {'field': 'history', 'localized': '历史'}, {'field': 'references', 'localized': '参考文献'}, {'field': 'assignee', 'localized': '受托人'}, {'field': 'country', 'localized': '国家'}, {'field': 'mapType', 'localized': '地图类型'}, {'field': 'place', 'localized': '地点'}, {'field': 'university', 'localized': '大学'}, {'field': 'committee', 'localized': '委员会'}, {'field': 'archiveID', 'localized': '存档ID'}, {'field': 'archiveLocation', 'localized': '存档位置'}, {'field': 'court', 'localized': '审判法院'}, {'field': 'studio', 'localized': '工作室'}, {'field': 'postType', 'localized': '帖子类型'}, {'field': 'citationKey', 'localized': '引用关键词'}, {'field': 'numberOfVolumes', 'localized': '总卷数'}, {'field': 'numPages', 'localized': '总页数'}, {'field': 'manuscriptType', 'localized': '手稿类型'}, {'field': 'reportType', 'localized': '报告类型'}, {'field': 'reporter', 'localized': '报告系统'}, {'field': 'reporterVolume', 'localized': '报告系统卷次'}, {'field': 'reportNumber', 'localized': '报告编号'}, {'field': 'abstractNote', 'localized': '摘要'}, {'field': 'documentNumber', 'localized': '文档编号'}, {'field': 'date', 'localized': '日期'}, {'field': 'runningTime', 'localized': '时长'}, {'field': 'publicationTitle', 'localized': '期刊'}, {'field': 'issue', 'localized': '期号'}, {'field': 'institution', 'localized': '机构组织'}, {'field': 'section', 'localized': '条文序号'}, {'field': 'label', 'localized': '标记'}, {'field': 'title', 'localized': '标题'}, {'field': 'caseName', 'localized': '案例名称'}, {'field': 'docketNumber', 'localized': '案号'}, {'field': 'archive', 'localized': '档案'}, {'field': 'scale', 'localized': '比例'}, {'field': 'code', 'localized': '法典'}, {'field': 'codeVolume', 'localized': '法典卷次'}, {'field': 'codeNumber', 'localized': '法典编号'}, {'field': 'codePages', 'localized': '法典页码'}, {'field': 'nameOfAct', 'localized': '法律名称'}, {'field': 'legalStatus', 'localized': '法律状态'}, {'field': 'billNumber', 'localized': '法案编号'}, {'field': 'genre', 'localized': '流派'}, {'field': 'presentationType', 'localized': '演稿类型'}, {'field': 'versionNumber', 'localized': '版本'}, {'field': 'edition', 'localized': '版本'}, {'field': 'rights', 'localized': '版权'}, {'field': 'applicationNumber', 'localized': '申请号'}, {'field': 'filingDate', 'localized': '申请日期'}, {'field': 'encyclopediaTitle', 'localized': '百科全书标题'}, {'field': 'shortTitle', 'localized': '短标题'}, {'field': 'legislativeBody', 'localized': '立法机构'}, {'field': 'series', 'localized': '系列'}, {'field': 'seriesText', 'localized': '系列文本'}, {'field': 'seriesTitle', 'localized': '系列标题'}, {'field': 'seriesNumber', 'localized': '系列编号'}, {'field': 'system', 'localized': '系统'}, {'field': 'callNumber', 'localized': '索书号'}, {'field': 'programmingLanguage', 'localized': '编程语言'}, {'field': 'websiteTitle', 'localized': '网站标题'}, {'field': 'websiteType', 'localized': '网站类型'}, {'field': 'network', 'localized': '网络'}, {'field': 'artworkMedium', 'localized': '艺术品媒介'}, {'field': 'artworkSize', 'localized': '艺术品尺寸'}, {'field': 'programTitle', 'localized': '节目名称'}, {'field': 'dateDecided', 'localized': '裁判时间'}, {'field': 'videoRecordingFormat', 'localized': '视频格式'}, {'field': 'forumTitle', 'localized': '论坛/列表服务标题'}, {'field': 'thesisType', 'localized': '论文类型'}, {'field': 'accessDate', 'localized': '访问时间'}, {'field': 'dictionaryTitle', 'localized': '词典标题'}, {'field': 'language', 'localized': '语言'}, {'field': 'firstPage', 'localized': '起始页'}, {'field': 'interviewMedium', 'localized': '采访媒体'}, {'field': 'episodeNumber', 'localized': '集数'}, {'field': 'audioFileType', 'localized': '音频文件类型'}, {'field': 'audioRecordingFormat', 'localized': '音频格式'}, {'field': 'pages', 'localized': '页码'}, {'field': 'issuingAuthority', 'localized': '颁发机构'}, {'field': 'dateEnacted', 'localized': '颁布日期'}, {'field': 'libraryCatalog', 'localized': '馆藏目录'}]

# 【我的出版物】 / My Publications
>>> zot.publications()
[]

# 【回收站】
>>> trash = zot.trash()
>>> len(trash)
2
分类信息和操作
# 【我的文库】 顶级分类
>>> colls_top = zot.collections_top()
>>> len(colls_top)
28
>>> for coll in colls_top:
...     print(coll['data']['name'])
...
单个B细胞全人抗体
比值对文章
质谱
meta分析
毕设论文

# 数据库分类
>>> collections = zot.collections()
>>> for col in collections:
...     print(col['data']['name'])
...
数据库
单个B细胞全人抗体
比值对文章
质谱
>>> collections[0]
{'key': 'YLK2EB2C', 'version': 2720, 'library': {'type': 'user', 'id': 9166338, 'name': 'phagelab', 'links': {'alternate': {'href': 'https://www.zotero.org/phagelab', 'type': 'text/html'}}}, 'links': {'self': {'href': 'https://api.zotero.org/users/9166338/collections/YLK2EB2C', 'type': 'application/json'}, 'alternate': {'href': 'https://www.zotero.org/phagelab/collections/YLK2EB2C', 'type': 'text/html'}, 'up': {'href': 'https://api.zotero.org/users/9166338/collections/CUN6PBIT', 'type': 'application/json'}}, 'meta': {'numCollections': 0, 'numItems': 1}, 'data': {'key': 'YLK2EB2C', 'version': 2720, 'name': '数据库', 'parentCollection': 'CUN6PBIT', 'relations': {}}}

# 查看特定分类
>>> zot.collection('YLK2EB2C')
{'key': 'YLK2EB2C', 'version': 2720, 'library': {'type': 'user', 'id': 9166338, 'name': 'phagelab', 'links': {'alternate': {'href': 'https://www.zotero.org/phagelab', 'type': 'text/html'}}}, 'links': {'self': {'href': 'https://api.zotero.org/users/9166338/collections/YLK2EB2C', 'type': 'application/json'}, 'alternate': {'href': 'https://www.zotero.org/phagelab/collections/YLK2EB2C', 'type': 'text/html'}, 'up': {'href': 'https://api.zotero.org/users/9166338/collections/CUN6PBIT', 'type': 'application/json'}}, 'meta': {'numCollections': 0, 'numItems': 1}, 'data': {'key': 'YLK2EB2C', 'version': 2720, 'name': '数据库', 'parentCollection': 'CUN6PBIT', 'relations': {}}}

# 查看分类的子分类
>>> colls_sub = zot.collections_sub('CUN6PBIT')
>>> len(colls_sub)
5
>>> for coll in colls_sub:
...     print(coll['data']['name'])
...
数据库
可开发性
规则
数据
特征生成

# 查看分类包含的条目
>>> colls_items = zot.collection_items('YLK2EB2C')
>>> for coll in colls_items:
...     print(coll['data'].get('key'),coll['data'].get('filename'))
...
HRX7KPSB Marks 和 Deane - 2020 - How repertoire data are changing antibody science.pdf
BWB6UUUV None
8BZTCRAJ Marks_Deane_2020_How repertoire data are changing antibody science.pdf
FDKYFV9D None
条目操作
# 当前 library / group 的记录总数
>>> zot.count_items()
1554

# 查看其中的元素, 默认返回 100 条
>>> items = zot.items(limit=1000)
>>> len(items)
100

# 使用 everything 返回所有
>>> items = zot.everything(zot.items())
>>> len(items)
1554
>>> for item in items:
...     if item['data']['itemType']=='journalArticle':
...         print(item['data']['title'])
...         print(item['data']['DOI'])
...
MicroRNAs from urinary exosomes as alternative biomarkers in the differentiation of benign and malignant prostate diseases
10.33393/jcb.2022.2317
How repertoire data are changing antibody science
10.1074/jbc.REV120.010181

# 根据 item id 查询特定的条目
>>> zot.item('8BZTCRAJ')
{'key': '8BZTCRAJ', 'version': 2722, 'library': {'type': 'user', 'id': 9166338, 'name': 'phagelab', 'links': {'alternate': {'href': 'https://www.zotero.org/phagelab', 'type': 'text/html'}}}, 'links': {'self': {'href': 'https://api.zotero.org/users/9166338/items/8BZTCRAJ', 'type': 'application/json'}, 'alternate': {'href': 'https://www.zotero.org/phagelab/items/8BZTCRAJ', 'type': 'text/html'}, 'up': {'href': 'https://api.zotero.org/users/9166338/items/FDKYFV9D', 'type': 'application/json'}}, 'meta': {'numChildren': 0}, 'data': {'key': '8BZTCRAJ', 'version': 2722, 'parentItem': 'FDKYFV9D', 'itemType': 'attachment', 'linkMode': 'imported_url', 'title': 'Marks_Deane_2020_How repertoire data are changing antibody science.pdf', 'accessDate': '2023-02-02T02:29:22Z', 'url': 'https://sci-hub.ru//downloads/2020-11-11/59/marks2020.pdf#navpanes=0&view=FitH', 'note': '', 'contentType': 'application/pdf', 'charset': '', 'filename': 'Marks_Deane_2020_How repertoire data are changing antibody science.pdf', 'md5': '9a37f590ef5c604d88829e5cdc47e479', 'mtime': 1675304962552, 'tags': [], 'relations': {}, 'dateAdded': '2023-02-02T02:29:22Z', 'dateModified': '2023-02-02T02:29:23Z'}}

# 查询特定的条目的子条目
>>> zot.children('8BZTCRAJ')
[]
数据模型

                "zh-CN": {
                        "itemTypes": {
                                "annotation": "注释",
                                "artwork": "艺术品",
                                "attachment": "附件",
                                "audioRecording": "音频",
                                "bill": "法案",
                                "blogPost": "博客帖子",
                                "book": "书籍",
                                "bookSection": "图书章节",
                                "case": "司法案例",
                                "computerProgram": "软件",
                                "conferencePaper": "会议论文",
                                "dictionaryEntry": "词条",
                                "document": "文档",
                                "email": "E-mail",
                                "encyclopediaArticle": "百科全书文章",
                                "film": "电影",
                                "forumPost": "论坛帖子",
                                "hearing": "听证会",
                                "instantMessage": "即时讯息",
                                "interview": "采访稿",
                                "journalArticle": "期刊文章",
                                "letter": "信件",
                                "magazineArticle": "杂志文章",
                                "manuscript": "手稿",
                                "map": "地图",
                                "newspaperArticle": "报纸文章",
                                "note": "笔记",
                                "patent": "专利",
                                "podcast": "播客",
                                "preprint": "预印本",
                                "presentation": "演示文档",
                                "radioBroadcast": "电台广播",
                                "report": "报告",
                                "statute": "法规",
                                "thesis": "学位论文",
                                "tvBroadcast": "电视广播",
                                "videoRecording": "视频",
                                "webpage": "网页"
                        },
                        "fields": {
                                "abstractNote": "摘要",
                                "accessDate": "访问时间",
                                "applicationNumber": "申请号",
                                "archive": "档案",
                                "archiveID": "存档ID",
                                "archiveLocation": "存档位置",
                                "artworkMedium": "艺术品媒介",
                                "artworkSize": "艺术品尺寸",
                                "assignee": "受托人",
                                "audioFileType": "音频文件类型",
                                "audioRecordingFormat": "音频格式",
                                "billNumber": "法案编号",
                                "blogTitle": "博客标题",
                                "bookTitle": "书名",
                                "callNumber": "索书号",
                                "caseName": "案例名称",
                                "citationKey": "引用关键词",
                                "code": "法典",
                                "codeNumber": "法典编号",
                                "codePages": "法典页码",
                                "codeVolume": "法典卷次",
                                "committee": "委员会",
                                "company": "公司",
                                "conferenceName": "会议名称",
                                "country": "国家",
                                "court": "审判法院",
                                "date": "日期",
                                "dateAdded": "添加日期",
                                "dateDecided": "裁判时间",
                                "dateEnacted": "颁布日期",
                                "dateModified": "修改日期",
                                "dictionaryTitle": "词典标题",
                                "distributor": "分发者",
                                "docketNumber": "案号",
                                "documentNumber": "文档编号",
                                "DOI": "DOI",
                                "edition": "版本",
                                "encyclopediaTitle": "百科全书标题",
                                "episodeNumber": "集数",
                                "extra": "其它",
                                "filingDate": "申请日期",
                                "firstPage": "起始页",
                                "forumTitle": "论坛/列表服务标题",
                                "genre": "流派",
                                "history": "历史",
                                "institution": "机构组织",
                                "interviewMedium": "采访媒体",
                                "ISBN": "ISBN",
                                "ISSN": "ISSN",
                                "issue": "期号",
                                "issueDate": "公告日期",
                                "issuingAuthority": "颁发机构",
                                "itemType": "类型",
                                "journalAbbreviation": "刊名缩写",
                                "label": "标记",
                                "language": "语言",
                                "legalStatus": "法律状态",
                                "legislativeBody": "立法机构",
                                "letterType": "信件类型",
                                "libraryCatalog": "馆藏目录",
                                "manuscriptType": "手稿类型",
                                "mapType": "地图类型",
                                "meetingName": "会议名称",
                                "nameOfAct": "法律名称",
                                "network": "网络",
                                "number": "号码",
                                "numberOfVolumes": "总卷数",
                                "numPages": "总页数",
                                "pages": "页码",
                                "patentNumber": "专利号",
                                "place": "地点",
                                "postType": "帖子类型",
                                "presentationType": "演稿类型",
                                "priorityNumbers": "优先申请号",
                                "proceedingsTitle": "会议论文集标题",
                                "programmingLanguage": "编程语言",
                                "programTitle": "节目名称",
                                "publicationTitle": "期刊",
                                "publicLawNumber": "公法号",
                                "publisher": "出版社",
                                "references": "参考文献",
                                "reporter": "报告系统",
                                "reporterVolume": "报告系统卷次",
                                "reportNumber": "报告编号",
                                "reportType": "报告类型",
                                "repository": "仓库",
                                "rights": "版权",
                                "runningTime": "时长",
                                "scale": "比例",
                                "section": "条文序号",
                                "series": "系列",
                                "seriesNumber": "系列编号",
                                "seriesText": "系列文本",
                                "seriesTitle": "系列标题",
                                "session": "会期",
                                "shortTitle": "短标题",
                                "studio": "工作室",
                                "subject": "主题",
                                "system": "系统",
                                "thesisType": "论文类型",
                                "title": "标题",
                                "university": "大学",
                                "url": "URL",
                                "versionNumber": "版本",
                                "videoRecordingFormat": "视频格式",
                                "volume": "卷次",
                                "websiteTitle": "网站标题",
                                "websiteType": "网站类型"
                        },
                        "creatorTypes": {
                                "artist": "艺术家",
                                "attorneyAgent": "律师/代理人",
                                "author": "作者",
                                "bookAuthor": "图书作者",
                                "cartographer": "制图人",
                                "castMember": "演员阵容",
                                "commenter": "评论人",
                                "composer": "创作者",
                                "contributor": "贡献者",
                                "cosponsor": "共同发起人",
                                "counsel": "顾问",
                                "director": "导演",
                                "editor": "编辑",
                                "guest": "宾客",
                                "interviewee": "采访对象",
                                "interviewer": "采访者",
                                "inventor": "发明人",
                                "performer": "表演者",
                                "podcaster": "播客",
                                "presenter": "报告人",
                                "producer": "制片人",
                                "programmer": "程序员",
                                "recipient": "接收者",
                                "reviewedAuthor": "审稿人",
                                "scriptwriter": "编剧",
                                "seriesEditor": "丛书编辑",
                                "sponsor": "发起人",
                                "translator": "译者",
                                "wordsBy": "作词"
                        }
                }
状态码

  • Successful GET requests will return a 200 OK status code.
  • Conditional GET requests may return 304 Not Modified.
  • For any read or write request, the server may return a 400 Bad Request, 404 Not Found, or 405 Method Not Allowed for an invalid request and 500 Internal Server Error or 503 Service Unavailable for a server-related issue. Authentication errors (e.g., invalid API key or insufficient privileges) will return a 403 Forbidden.
  • Passing an Expect header, which is unsupported, will result in a 417 Expectation Failed response.
  • Library/object versioning or Zotero-Write-Token errors will result in 412 Precondition Failed or 428 Precondition Required.
  • 429 Too Many Requests indicates that the client has been rate-limited.
https://pyzotero.readthedocs.io/en/latest/#
https://www.zotero.org/support/dev/web_api/v3/start

本文使用 Zhihu On VSCode 创作并发布
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|办公问答网

GMT+8, 2025-3-16 00:35 , Processed in 0.114042 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc. Templated By 【未来科技 www.veikei.com】设计

快速回复 返回顶部 返回列表