Created
December 18, 2022 00:57
-
-
Save longemen3000/24e59ef520b57eaee60e7230b292bb25 to your computer and use it in GitHub Desktop.
doi to bibtex, Julia Version
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
#tested on Julia 1.8.3 | |
using Downloads #stdlib, other versions use HTTP | |
const DOI2BIB_CACHE = Dict{String,String}() | |
function doi2bib(doi::String) | |
if haskey(DOI2BIB_CACHE,doi) | |
return DOI2BIB_CACHE[doi] #caching requests | |
end | |
headers = ["Accept"=>"application/x-bibtex", | |
"charset" => "utf-8"] | |
url = "https://dx.doi.org/" * doi | |
out = IOBuffer() | |
r = Downloads.request(url, output = out, method = "GET",headers = headers) | |
if r.status == 200 | |
res = String(take!(out)) | |
else | |
res = "" | |
end | |
DOI2BIB_CACHE[doi] = res | |
return res | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment