Skip to content

Instantly share code, notes, and snippets.

@colin-daniels
Created November 13, 2019 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colin-daniels/60a917bbaaa0e418c41bb260fb57bb58 to your computer and use it in GitHub Desktop.
Save colin-daniels/60a917bbaaa0e418c41bb260fb57bb58 to your computer and use it in GitHub Desktop.
Fetch publications given an ORCID and turn them into a markdown-formatted publication list
#!/bin/bash
# dependencies: jq, grep, sed, tr, curl, and perl URI::Escape (or replace url_encode function)
set -e
orcid="0000-0002-3512-7146"
# name to match when bolding in author list, should be abbreviated as in
# "Given Names Last" -> "G. N. Last"
match_name="C. Daniels"
# whether to output as a numbered list instead of unordered (i.e. bullet points)
output_numbered_list=true
function url_encode {
# note: requires `perl-uri` on arch linux
perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "${1?"Missing argument"}"
}
function echoerr {
echo "$@" 1>&2
}
function get_dois_from {
jq -r "
# get the DOI for a ORCID group entry
def group_doi:
.groupId as \$gid |
.externalIdentifiers | map(
# we are only looking for DOIs here
select(
.externalIdentifierType.value == \"doi\" and
.relationship.value == \"self\"
) |
# actual DOI string (e.g., '10.1021/acsnano.9b05817')
.externalIdentifierId.value
) |
if length == 0 then
error(\"Missing DOI for ORCID entry [groupId = \(\$gid)]. Please edit works.json and try again.\")
elif length > 1 then
error(\"More than one DOI for ORCID entry [groupId = \(\$gid)]. Please edit works.json and try again.\")
else
.[0]
end;
# just get the associated DOI for each group entry
.groups[] | group_doi
" "${1?"missing input json file argument"}"
}
if [ -f "works.json" ]; then
echoerr "Reusing existing works.json for ORCID $orcid"
else
echoerr "Fetching works.json for ORCID $orcid"
# get works in order of latest-oldest
curl "https://orcid.org/$orcid/worksPage.json?offset=0&sort=date&sortAsc=false" \
-H 'Accept: application/json, text/plain, */*' \
-H "Referer: https://orcid.org/$orcid" \
> works.json
fi
# get dois
echoerr "Getting DOIs from works.json"
get_dois_from works.json > works.txt
echoerr "Got $(wc -l < works.txt) DOIs from works.json"
# get data from crossref
echoerr "Getting info from crossref for each DOI"
while IFS="" read -r doi; do
# url encode because /'s
url_doi=$(url_encode "$doi")
# output filenames
xref_json="doi-$url_doi.json"
xref_bib="doi-$url_doi.bib"
if [ -f "$xref_json" ] && [ -f "$xref_bib" ]; then
echoerr " $doi already processed, skipping"
continue
fi
echoerr " Processing $doi"
curl "https://api.crossref.org/v1/works/$url_doi" > "$xref_json"
sleep 0.25
curl "https://search.crossref.org/citation?format=bibtex&doi=$url_doi" > "$xref_bib"
sleep 0.75
done < works.txt
# build markdown publication file...very hackily since this is taking too much time
echoerr "Building publications.md"
pub_idx=0
while IFS="" read -r doi; do
echoerr " Processing $doi"
pub_idx=$(( pub_idx + 1 ))
url_doi=$(url_encode "$doi")
xref_json="doi-$url_doi.json"
xref_bib="doi-$url_doi.bib"
authors=$(
jq -r --arg name "$match_name" '
def abbreviate:
split(" ") | map(.[:1] + ".") | join(" ");
.message.author | map(
"\(.given | abbreviate) \(.family)" |
# bold name in author list if it matches
if . == $name then
"**\(.)**"
else
.
end
) | join(", ")' "$xref_json"
)
title=$(jq -r '.message.title[0]' "$xref_json")
journal=$(jq -r '.message | .["container-title"][0]' "$xref_json")
year=$(grep 'year = ' "$xref_bib" | tr -d -c '[0-9]')
volume=$(grep 'volume = ' "$xref_bib" | sed -e 's/^.*{//' -e 's/}.*$//')
pages=$(grep 'pages = ' "$xref_bib" | sed -e 's/^.*{//' -e 's/}.*$//')
markdown="$authors, _${title}_, $journal"
if [ ! -z "$volume" ]; then markdown+=" $volume"; fi
markdown+=", "
if [ ! -z "$pages" ]; then markdown+="$pages "; fi
markdown+="[$doi](https://doi.org/$url_doi)"
if [ ! -z "$year" ]; then markdown+=" ($year)"; fi
markdown+="."
markdown=$(sed 's/--/–/g' <<< "$markdown")
if [ "$output_numbered_list" = true ]; then
echo "$pub_idx. $markdown"
else
echo "* $markdown"
fi
done < works.txt > publications.md
echoerr "Done"
@colin-daniels
Copy link
Author

Output looks something like this:

  1. J. Overbeck, G. Borin Barin, C. Daniels, M. L. Perrin, L. Liang, O. Braun, R. Darawish, B. Burkhardt, T. Dumslaff, X. Wang, A. Narita, K. Müllen, V. Meunier, R. Fasel, M. Calame, P. Ruffieux, Optimized Substrates and Measurement Approaches for Raman Spectroscopy of Graphene Nanoribbons, physica status solidi (b), 1900343 10.1002/pssb.201900343 (2019).
  2. J. Overbeck, G. B. Barin, C. Daniels, M. L. Perrin, O. Braun, Q. Sun, R. Darawish, M. De Luca, X. Wang, T. Dumslaff, A. Narita, K. Müllen, P. Ruffieux, V. Meunier, R. Fasel, M. Calame, A Universal Length-Dependent Vibrational Mode in Graphene Nanoribbons, ACS Nano, 10.1021/acsnano.9b05817 (2019).
  3. D. Liu, C. Daniels, V. Meunier, A. G. Every, D. Tománek, In-plane breathing and shear modes in low-dimensional nanostructures, Carbon 157, 364–370 10.1016/j.carbon.2019.10.041 (2020).
  4. C. Sánchez‐Sánchez, T. Dienel, A. Nicolaï, N. Kharche, L. Liang, C. Daniels, V. Meunier, J. Liu, X. Feng, K. Müllen, J. R. Sánchez‐Valencia, O. Gröning, P. Ruffieux, R. Fasel, On‐Surface Synthesis and Characterization of Acene‐Based Nanoribbons Incorporating Four‐Membered Rings, Chemistry – A European Journal 25, 12074–12082 10.1002/chem.201901410 (2019).
  5. N. W. Hackney, D. Tristant, A. Cupo, C. Daniels, V. Meunier, Shell model extension to the valence force field: application to single-layer black phosphorus, Physical Chemistry Chemical Physics 21, 322–328 10.1039/c8cp05923c (2019).
  6. O. Gröning, S. Wang, X. Yao, C. A. Pignedoli, G. Borin Barin, C. Daniels, A. Cupo, V. Meunier, X. Feng, A. Narita, K. Müllen, P. Ruffieux, R. Fasel, Engineering of robust topological quantum phases in graphene nanoribbons, Nature 560, 209–213 10.1038/s41586-018-0375-9 (2018).
  7. J. Owens, C. Daniels, A. Nicolaï, H. Terrones, V. Meunier, Structural, energetic, and electronic properties of gyroidal graphene nanostructures, Carbon 96, 998–1007 10.1016/j.carbon.2015.10.042 (2016).
  8. C. Daniels, A. Horning, A. Phillips, D. V. P. Massote, L. Liang, Z. Bullard, B. G. Sumpter, V. Meunier, Elastic, plastic, and fracture mechanisms in graphene materials, Journal of Physics: Condensed Matter 27, 373002 10.1088/0953-8984/27/37/373002 (2015).
  9. Z. J. Qi, C. Daniels, S. J. Hong, Y. W. Park, V. Meunier, M. Drndić, A. T. C. Johnson, Electronic Transport of Recrystallized Freestanding Graphene Nanoribbons, ACS Nano 9, 3510–3520 10.1021/nn507452g (2015).
  10. A. Nicolaï, J. Monti, C. Daniels, V. Meunier, Electrolyte Diffusion in Gyroidal Nanoporous Carbon, The Journal of Physical Chemistry C 119, 2896–2903 10.1021/jp511919d (2015).
  11. C. Daniels, Z. Bullard, E. C. Girão, V. Meunier, Emergent magnetism in irradiated graphene nanostructures, Carbon 78, 196–203 10.1016/j.carbon.2014.06.072 (2014).
  12. Z. Bullard, E. Costa Girão, C. Daniels, B. G. Sumpter, V. Meunier, Quantifying energetics of topological frustration in carbon nanostructures, Physical Review B 89, 10.1103/physrevb.89.245425 (2014).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment