Skip to content

Instantly share code, notes, and snippets.

@pgwillia
Created July 31, 2025 22:38
Show Gist options
  • Save pgwillia/3c2bd97425b4c1c3d213c50ee8ba93ab to your computer and use it in GitHub Desktop.
Save pgwillia/3c2bd97425b4c1c3d213c50ee8ba93ab to your computer and use it in GitHub Desktop.
Use DataCite API to complete Old URL column for ISTL journal migration
require 'net/http'
require 'json'
require 'csv'
CSV.open('istl_url.csv', 'wb') do |csv|
csv << ['doi', 'url']
File.open("istl_doi.txt") do |f|
f.each_line(chomp: true) do |doi|
source = URI.parse("https://api.datacite.org/dois/#{doi}")
resp = Net::HTTP.get_response(source)
data = resp.body
result = JSON.parse(data).to_h
csv << [result['data']['id'], result['data']['attributes']['url']] # needs error handling, I'm manually editing istl_doi.txt to keep this going
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment