Code Monkey home page Code Monkey logo

bibcites's Introduction

bibcites

Command-line utility which reads a BibTeX file, finds entries with a DOI, looks up the corresponding number of citations using OpenCitations, saves this number to the addendum field of each entry, and writes results to a new BibTex file.

Installation

python -m pip install bibcites should do the trick.

Usage

Usage: bibcites [OPTIONS] BIBFILE

  Reads a BibTeX file (BIBFILE), finds entries with a DOI, looks up the
  corresponding number of citations using OpenCitations
  (https://opencitations.net), saves this number to the 'addendum' field of
  each entry, and writes results to a new BibTex file.

  Optionally, using option -s, print out a list of entries with DOI sorted by
  number of citations.

Options:
  -o TEXT     output BibTex file
  -f TEXT     format of text to save to 'addendum' field
  -s          print list sorted by cites
  -v          enable verbose output
  -t TEXT     only process entries of this type (may be used several times to
              process several types)
  -n INTEGER  size limit for OpenCitations queries
  --help      Show this message and exit.

bibcites myfile.bib will read the contents of myfile.bib, look up all entries with a DOI field in OpenCitations, append “[X citations]” to the addendum field of each entry, and save the result to myfile_withcites.bib

  • To get verbose output, use -v option.
  • To set a custom file name for the output BibTeX file, use the -o <customfilename> option.
  • To set a custom format to the addendum field, use the -f option, e.g., -f 'Cited {:s} times'. Use the {:s} specifier because the citation count is a string.
  • To print out a list of processed entries, sorted by decreasing number of citations, use the -s option.
  • To process only entries of certain types, use the -t option one or more times, e.g., -t article -t book.
  • To limit the size of OpenCitations queries, use -n option (default is -n 50).

Contact

All questions and suggestions are welcome and should be directed at Mathieu Daëron.

bibcites's People

Contributors

mdaeron avatar

Watchers

 avatar

bibcites's Issues

Error on first run

Hi Mathieu,

I wanted to try the package out on my break on my entire bib database. I installed it via pip install (for the user) and ran it, but it didn't generate a result.

Hope it helps improve the package :).

Here's the trace:

> bibcites references.bib
Traceback (most recent call last):
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 107, in expand_string
    self.strings[name])
KeyError: 'aug'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/japhir/.local/bin/bibcites", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibcites/__init__.py", line 40, in cli
    db = bibtexparser.load(bibtex_file)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/__init__.py", line 69, in load
    return parser.parse_file(bibtex_file)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bparser.py", line 169, in parse_file
    return self.parse(file.read(), partial=partial)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bparser.py", line 147, in parse
    self._expr.parseFile(bibtex_file_obj)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibtexexpression.py", line 278, in parseFile
    return self.main_expression.parseFile(file_obj, parseAll=True)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 1859, in parse_file
    return self.parse_string(file_contents, parseAll)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 1097, in parse_string
    loc, tokens = self._parse(instring, 0)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 787, in _parseNoCache
    loc, tokens = self.parseImpl(instring, preloc, doActions)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 4695, in parseImpl
    return super().parseImpl(instring, loc, doActions)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 4603, in parseImpl
    loc, tokens = self_expr_parse(instring, loc, doActions)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 787, in _parseNoCache
    loc, tokens = self.parseImpl(instring, preloc, doActions)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 4003, in parseImpl
    return e._parse(
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 824, in _parseNoCache
    tokens = fn(instring, tokensStart, retTokens)
  File "/usr/lib/python3.10/site-packages/pyparsing/core.py", line 282, in wrapper
    ret = func(*args[limit:])
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bparser.py", line 187, in <lambda>
    lambda s, l, t: self._add_entry(
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bparser.py", line 277, in _add_entry
    d[self._clean_field_key(key)] = self._clean_val(fields[key])
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bparser.py", line 228, in _clean_val
    return as_text(val)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 270, in as_text
    return text_string_or_expression.get_value()
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 231, in get_value
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 231, in <listcomp>
    return ''.join([BibDataString.expand_string(s) for s in self.expr])
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 197, in expand_string
    return string_or_bibdatastring.get_value()
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 178, in get_value
    return self._bibdatabase.expand_string(self.name)
  File "/home/japhir/.local/lib/python3.10/site-packages/bibtexparser/bibdatabase.py", line 109, in expand_string
    raise(UndefinedString(name))
bibtexparser.bibdatabase.UndefinedString: 'aug'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.