Command line clients

From refbase

Revision as of 19:57, 14 March 2007; view current revision
←Older revision | Newer revision→

This page documents the refbase command line clients that come with refbase >v0.8.0.

Contents

'refbase' command line client

The 'refbase' command line client allows you to search a refbase online database from the command line and retrieve results in various formats. By default, found results are returned as citations in plain text format, but search results can easily be saved as HTML, RTF, PDF, LaTeX or structured text (Markdown). In addition, found results can be exported to BibTeX, Endnote, RIS or XML (MODS, SRW, OpenOffice.org/OpenDocument) formats.

Besides using the refbase CLI to perform a quick database query from the shell, the command line client allows for easy integration of a refbase database into a custom workflow. Possible applications could be automatic backups via scheduled cron jobs or automatic creation and update of static publication lists that employ a custom HTML layout.

Requirements

The 'refbase' command line client requires:

Installation

  • Install required Perl modules (if missing)
Info about installing Perl modules from CPAN is available here and here. Here's a quick guide: you can check if the above mentioned CPAN modules are already installed on your system using these commands from your shell:
perl -MLWP::UserAgent -e 1
perl -MHTTP::Request::Common -e 1
perl -MHTTP::Response -e 1
perl -MHTTP::Cookies -e 1
perl -MURI::URL -e 1
If these commands don't return any error messages, you have the required modules. If you do see some error messages, it's still possible that these modules are installed on your system, but that they are not in your path, which can be displayed with:
perl -e "print qq(@INC)"
If the required CPAN modules are not installed on your system, you should be able to install them using the following commands:
perl -MCPAN -e 'install LWP::UserAgent'
perl -MCPAN -e 'install HTTP::Request::Common'
perl -MCPAN -e 'install HTTP::Response'
perl -MCPAN -e 'install HTTP::Cookies'
perl -MCPAN -e 'install URI::URL'
The installation process will try to take care of any dependencies. However, if your module installation fails because of other missing modules, checkout the error messages and try to install the mentioned modules first, then try again to install the above mentioned modules.
  • Download 'refbase' CLI
Download the latest script version of the refbase command line client from the SourceForge SVN as source text.
  • Copy 'refbase' CLI to executable path
Put the downloaded script file within an executable path and make sure that the file itself is executable.

You should now be able to type refbase at the command line to invoke the 'refbase' command line client. See below for more info about the required syntax.

Syntax

For help with the syntax type:

refbase -h
refbase --help

This will print the usage screen:

refbase command line client, v1.1 by Matthias Steffens, http://cli.refbase.net/

Usage:   refbase [OPTIONS]

Notes:   - At least one query option must be given and unrecognized options will be ignored.
         - If multiple options are given, they will by default be connected with 'AND'. Use
           '--query=or' to connect multiple options with 'OR'.
         - Options syntax: [OPTION]=[VALUE], e.g. '-a=steffens' or '--author="steffens, m"'.
         - Returns up to '--rows' number of records beginning with '--start'. If all given
           query options are empty, all database records will be returned.
         - Note that '--records' assumes a list of full record serials separated by non-digit
           characters while '--serial' allows for partial matches.
         - For each option, default values can be specified at the top of the script.
           Current defaults are given in parentheses.

General Options:   -h, --help        - display this help text
                   -v, --version     - display version information
                   -X, --examples    - display usage examples

Query Options:     -a, --author      - search author field (' ')
                   -b, --abstract    - search abstract field (' ')
                   -c, --citekey     - search cite_key field, requires '-u, --userid' (' ')
                   -d, --date        - search by creation date (' ')
                   -e, --area        - search area field (' ')
                   -f, --thesis      - search thesis field (' ')
                   -i, --contribid   - search contribution_id field (' ')
                   -j, --journal     - search abbrev_journal field (' ')
                   -k, --keywords    - search keywords field (' ')
                   -l, --location    - search location field (' ')
                   -m, --marked      - search marked field, requires '-u, --userid' (' ')
                   -n, --notes       - search notes field (' ')
                   -p, --publication - search publication field (' ')
                   -q, --query       - query type, possible values: and, or ('and')
                   -r, --records     - search serial field (' ')
                   -s, --selected    - search selected field, requires '-u, --userid' (' ')
                   -t, --title       - search title field (' ')
                   -u, --userid      - join with user-specific data from user ID (' ')
                   -w, --where       - search by using a raw sql where clause (' ')
                   -x, --type        - search type field (' ')
                   -y, --year        - search year field (' ')
                   -z, --serial      - search serial field (partial matches) ('.+')

Output Options:    -C, --style       - citation style (' ')
                   -F, --format      - output format ('ascii')
                                       possible values: html, rtf, pdf, latex, markdown, ascii,
                                                        bibtex, endnote, ris, mods, srw, odf
                   -L, --showlinks   - hide/display links column in html output ('1')
                                       possible values: 0, 1
                   -O, --order       - sort order of returned records ('author')
                                       possible values: author, year, type, type-year
                   -Q, --showquery   - hide/display SQL query in ASCII output ('0')
                                       possible values: 0, 1
                   -R, --rows        - number of records to be returned (' ')
                   -S, --start       - number of first record to be returned ('1')
                   -V, --view        - view type of html output ('web')
                                       possible values: web, print

Server Options:    -H, --host        - URL of the refbase database ('http://polaris.ipoe.uni-kiel.de/refs/')
                                       defined shortcuts: beta, default, local
                   -P, --password    - password for given user account (' ')
                   -U, --user        - login email address of an existing refbase user (' ')

Examples

To view some usage examples type:

refbase -X
refbase --examples

This will print the examples screen:

--------------------------------------------------------------------------------
REFBASE USAGE EXAMPLES:
--------------------------------------------------------------------------------

1) Find all records where the author field contains 'mock' AND the year field
   contains '2005':

   refbase -a=mock -y=2005

--------------------------------------------------------------------------------

2) Find all records where the author field contains 'mock' OR the title field
   contains 'photo', and display 10 records starting with the 21st record in the
   result set:

   refbase -a=mock -t=photo -q=or -R=10 -S=21

--------------------------------------------------------------------------------

3) Export records with serial numbers '1', '12' and '34' to Endnote format and
   save them to a file named 'export.enw':

   refbase -r=1,12,34 -F=endnote > export.enw

--------------------------------------------------------------------------------

4) Return up to 50 records that were selected by a user with a user ID '2' in
   RTF format using citation style "Ann Glaciol" and sorting them first by
   record type, then by year, and save results to a file named 'citations.rtf':

   refbase -s=yes -u=2 -R=50 -F=rtf -C="Ann Glaciol" -O=type-year > citations.rtf

--------------------------------------------------------------------------------

5) Find all records which were modified today by a user named "admin" and where
   the location field contains 'msteffens' (note the use of the '-w' option to
   specify a custom WHERE clause):

   refbase -w='modified_date = CURDATE() AND modified_by RLIKE "admin"' -l=msteffens

--------------------------------------------------------------------------------

Appending to a file (export all records)

PHP has memory and time-execution limits, which prevent VERY large export sets. These can pose a hurdle for those who wish to export a substantial portion of their database (for example to share with Endnote or BibTeX using colleagues). The following shell script will export all references which have serial numbers between 1 and 10,000 (one-by-one, appended to the same file):

for ((i=1; i<=10000;i++))
do
  ./refbase -r=$i -F=bibtex >> output.bib
done

The script may be trivially modified with a different range of serial numbers or to export to a different tagged format (such as "endnote").

You may also want to modify it to request more than one record at once and/or to wait between requests.

Current limitations

  • Currently, this utility supports search & retrieve, but does not support update actions such as add, edit or delete.
  • This script is currently just an interface to show.php, which for example does not support arbitrary sort orders.
  • Specifying the record offset (--start) as well as the number of records to be returned (--rows) will only work for the formats html, rtf, pdf, latex, markdown, ascii and srw, since the other formats are designed to always export the entire result set. Note that for html, --start is adjusted to the next lower value that is an exact multiple of --rows (which ensures correct behaviour of the browse links).
  • The authentication mechanism is currently limited in that a given password will be transferred as parameter in the POST request.


'refbase_import' command line client

The 'refbase_import' command line client enables you to upload data in various formats to a refbase online database from the command line. This allows for easy integration of a refbase database into a custom workflow. A possible application could be the automatic retrieval & import of newly added records from PubMed via a scheduled cron job.

Requirements

The 'refbase_import' command line client requires:

Installation

  • Install required Perl modules (if missing)
See the 'refbase' command line client for a detailed description on how to install any required Perl modules.
  • Download 'refbase_import' CLI
Download the latest script version of the 'refbase_import' command line client from the SourceForge SVN as source text.
  • Copy 'refbase_import' CLI to executable path
Put the downloaded script file within an executable path and make sure that the file itself is executable.

You should now be able to type refbase_import at the command line to invoke the 'refbase_import' command line client. See below for more info about the required syntax.

Syntax

For help with the syntax type:

refbase_import -h
refbase_import --help

This will print the usage screen:

refbase_import command line client, v1.0 by Matthias Steffens, http://cli.refbase.net/

Usage:   refbase_import [OPTIONS] [FILE]

Notes:   - Two import modes are supported:
           1) '--type=data' requires an import FILE to be specified;
              for supported import formats, see: http://import.refbase.net/
           2) '--type=pmid' requires the '-p|--pmid' option with one or more PubMed IDs
              delimited by any non-digit characters.
         - Options syntax: [OPTION]=[VALUE], e.g. '-p=16351846' or '--pmid="16351846 16783713"'.
         - For each option, default values can be specified at the top of the script.
           Current defaults are given in parentheses.

General Options:   -h, --help       - display this help text
                   -v, --version    - display version information
                   -X, --examples   - display usage examples

Import Options:    -b, --skipbad    - skip records with unrecognized data format ('0')
                                      possible values: 0, 1
                   -i, --import     - import all or only some records ('all')
                                      possible values: all, only
                   -p, --pmid       - PubMed IDs of records to import (' ')
                   -r, --records    - positional numbers and/or ranges of records to import ('1')
                                      requires the '--import=only' option
                   -t, --type       - import type ('data')
                                      possible values: data, pmid

Server Options:    -H, --host       - URL of the refbase database ('http://beta.refbase.net/')
                                      defined shortcuts: default, local
                   -P, --password   - password for given user account (' ')
                   -U, --user       - login email address of an existing refbase user with
                                      import permissions (' ')

Examples

To view some usage examples type:

refbase_import -X
refbase_import --examples

This will print the examples screen:

 --------------------------------------------------------------------------------
 REFBASE_IMPORT USAGE EXAMPLES:
 --------------------------------------------------------------------------------

 1) Import BibTeX records from file 'import.bib' using the defaults defined
    within the refbase_import script:
 
    refbase_import import.bib
 
 --------------------------------------------------------------------------------

 2) Import all Endnote records given in file 'import.enw' into your default
    refbase database:
 
    refbase_import -t=data -i=all import.enw
 
 --------------------------------------------------------------------------------

 3) Take RIS records from file 'import.ris' but import only the first three as
    well as the fifth and the tenth record into your local refbase database:
 
    refbase_import -H=local -t=data -i=only -r=1-3,5,10 import.ris
 
 --------------------------------------------------------------------------------

 4) Fetch two records from PubMed via their PMID identifier (in this example,
    records with PMIDs 16351846 and 16783713) and import them into your local
    refbase database:
 
    refbase_import -H=local -t=pmid -p=16351846,16783713
 
 --------------------------------------------------------------------------------

Current limitations

  • The character encoding of your import data must match the encoding of your refbase database (i.e., 'latin1' or 'utf8').
  • The authentication mechanism is currently limited in that a given password will be transferred as parameter in the POST request.