Skip to content

OpenDevEd/zotero-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zotero-lib

Introduction

Tools for working with the APIs of Zotero and Zenodo (zotzen)

This repository is part of a set of repositories, see here. Currently, this set contains a number of libraries

(The above tools can also be installed as command-line tools (CLI) with npm -g.)

And a web application

This code builds on earlier code for zotero-cli, which was developed by @bjohas, @retorquere and @a1diablo.

Installation

Install this library in a module with

npm install zotero-lib
yarn add zotero-lib

or as global CLI

npm install -g zotero-lib
yarn global add zotero-lib

View entry on npm

Use of the library and the CLI

The directory tests/ contains a number of tests that illustrate the use of the npm library. The file tests/test_cli.sh has examples for use of the library from the command line.

CLI Documentation

The zotero-cli allows you to access zoter from cmd line, it allows you to automate redundant taskse easily

Basic usage

Help

zotero-lib -h
zotero-lib --help

This will print help for all commands and options accepted by zotero-lib

Version

zotero-lib -v
zotero-lib --version

This will print the version of cli you have installed

create

This allows you to create item(s). You can create items in two different ways either by providing file containg json or json items as string

Both of these options can be used by providing following arguments

  • --files - this accepts text files containing json
  • --items - this accepts items as json string

Note: You must use only one of these at a time

Examples

zotero-lib create --files filepath.txt
zotero-lib create --items '{"title": "zotero item 1", "itemType": "book"}' '{"title": "zotero item 2", "itemType": "book"}'

update

This sub-command can be used to update existing items

zotero-lib update --key key-here --json '{"title": "zotero item 1 updat", "itemType": "book"}'
zotero-lib update --key key-here --file filepath.txt

You can also specify option replace which completely replace existing item and only keep provided information

zotero-lib update --replace --key key-here --json '{"title": "zotero item 1 updat", "itemType": "book"}'

item

This sub-command has various use cases

To fetch item

zotero-lib item --key key-here

To add files

zotero-lib item --key key-here --addfiles test.json

items

This sub-command can be used to fetch items with various filters

zotero-lib items --filter '{"limit": 10}'

collection

collections

publications

tags

attachment

types

groups

fields

searches

key

field

This sub-command can be used to fetch field information

zoetro-lib field --key key-here --field field-name

Modify field information

zoetro-lib field --key key-here --field field-name --value new-value

Or with --extra to fetch extra information

zoetro-lib field --extra --key key-here --field field-name

And modify extra information

zoetro-lib field --extra --key key-here --field field-name --value new-value

update-url

get-doi

update-doi

enclose-item

attach-link

attach-note

kciaka

bibliography

Local Database Syncing

You can use this cli to locally backup your online zotero library. The db cmd allows you to sync online library in local sqlite database. On first run all online records are synced into local database. On subsequent runs only those records are fetched, which were modifed since last sync.

The underlying database is SQLite. You dont need to install any server or anything it will work out of box as SQLite comes bundled with this cli.

To use this cmd you need to provide your db name along with one or more options. The options which you can specify are detailed below.

--sync make local db synced with online library
--lookup allow you to lookup specific items in the local db
--keys this must be used with --lookup to specify specfic keys you want to locate
--lockfile name of lock file to be used, default is "sync.lock" --lock-timeout if a lock file already exist, how much older it should be to classify it as outdated, if its outdated it will be removed and a new one will be generated --export-json=<file-name.json> export localdb as json with given file-name.json
--demon=<valid-cron-pattern this will make the sync process run in demon mode, where it will peridically sync by itself, see https://crontab.guru to learn about crontab pattern
--errors this will list all inconsistent items which have non zero children and non zero references

These options are optional and can be combined as required. If all options are specified then they will be read/applied in above order.

Examples

To sync given db file backup.db with online version

zotero-cli db backup.db --sync

To export give db file backup.db as json file ./backup.json

zotero-cli db backup.db --export-json="./backup.json"

You can combine previous two steps in one cmd

zotero-cli db backup.db --sync --export-json="./backup.json"

Also see

zotero-api-client (With hindsight we might have built on zotero-api-client - we might still rebuild our code to use zotero-api-client.)