Created
April 14, 2015 10:41
-
-
Save njbart/3f0b75e2574f221f3a0c to your computer and use it in GitHub Desktop.
Replace DOIs by shortDOIs in CSL JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env Rscript | |
library("jsonlite") | |
filename <- commandArgs(TRUE)[1] | |
bibdata <- fromJSON(filename, simplifyVector = FALSE, simplifyDataFrame = FALSE, simplifyMatrix = FALSE) | |
for (n in seq_along(bibdata)) { | |
if (exists('DOI', where=bibdata[[n]])) | |
{ | |
getshortdoi <- paste0("curl -sS http://shortdoi.org/", bibdata[[n]]$DOI, "?format=json | grep ShortDOI | cut -f 4 -d '\"'") | |
shortdoi <- try(system(getshortdoi, intern = TRUE)) | |
if (shortdoi=="") {} else {bibdata[[n]]$DOI <- shortdoi} | |
} | |
# else {} | |
} | |
write(toJSON(bibdata, auto_unbox = TRUE), file = filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment