From 3e4bc62b7eda9f391d9fd8df9972f2e7ff4c08b4 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Thu, 19 Dec 2024 18:14:36 -0500 Subject: [PATCH] Add helper scripts to import bibliography --- tools/import_doi | 37 +++++++++++++++++++++++++++++++++++++ tools/import_doi_all | 10 ++++++++++ 2 files changed, 47 insertions(+) create mode 100755 tools/import_doi create mode 100755 tools/import_doi_all diff --git a/tools/import_doi b/tools/import_doi new file mode 100755 index 0000000..c2cd7b3 --- /dev/null +++ b/tools/import_doi @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Provide DOIs to import +# +# Uses "academic" (pip install academic) and bibtool (apt install bibtool) + +set -eu + +topd=$(dirname "$0")/.. +pubdir="$topd/content/publications" +bibs="$pubdir/publications.bib" + + +echo "Storing BibTeX records into $bibs" +for arg in "$@"; do + doi=$(echo "$arg" | sed -e 's,https*://.*doi\.org/,,g') + if grep -q "$doi" "$bibs" 2>/dev/null; then + echo "DOI $doi already known to $bibs. skipping" + continue + fi + mkdir -p "$pubdir" + touch "$bibs" + if ! curl --silent -L -d "" --header "Accept: application/x-bibtex; charset=utf-8" https://doi.org/$doi | sed -e 's,%2F,/,g' >> "$bibs"; then + echo "ERROR: failed to fetch bibtex for doi $doi" + exit 1 + fi +done + +bibtool -s -i "$bibs" -o "$bibs" + +if [ -e "$bibs" ]; then + echo "Importing" + academic import --compact "$bibs" "$pubdir" + git status "$pubdir" +else + echo "No $bibs, nothing todo" +fi diff --git a/tools/import_doi_all b/tools/import_doi_all new file mode 100755 index 0000000..9e41752 --- /dev/null +++ b/tools/import_doi_all @@ -0,0 +1,10 @@ +#!/bin/bash +# +# one time use script to import all already existing in plain text publications +# + +# +# TODO: ideally for all THOSE added entries we should add a tag "repronim" or alike so we could +# add also related publications and then separate from those which are associated directly with ReproNim +# +grep 'doi:' content/about/publications.md | sed -e 's,.*(https://doi.org/\(.*\)).*,\1,g' | xargs tools/import_doi