Skip to content

Instantly share code, notes, and snippets.

@longemen3000
Created December 18, 2022 00:57
Show Gist options
  • Save longemen3000/24e59ef520b57eaee60e7230b292bb25 to your computer and use it in GitHub Desktop.
Save longemen3000/24e59ef520b57eaee60e7230b292bb25 to your computer and use it in GitHub Desktop.
doi to bibtex, Julia Version
#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