-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisbn_noid_doi_id.rb
43 lines (40 loc) · 1.23 KB
/
isbn_noid_doi_id.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script given a list of ISBNs, it generates a CSV
# of ISBN,NOID,DOI[,identifier]
csv_file = ARGV[0]
isbn_list = ARGV[1..-1]
=begin
puts "ISBN,NOID,DOI,ID"
isbn_list.each do |isbn|
monograph_list = Monograph.where(isbn_numeric: [isbn])
if monograph_list.empty?
puts "#{isbn},,,"
else
monograph = monograph_list.first
if monograph.identifier.empty?
puts "#{isbn},#{monograph.id},https://doi.org/#{monograph.doi},"
else
puts "#{isbn},#{monograph.id},https://doi.org/#{monograph.doi},#{monograph.identifier.first}"
end
end
end
=end
#csv_file = File.join(File.dirname(__FILE__), "isbn_noid_doi_id.csv")
#csv_file = Tempfile.new(["isbn_noid_doi_id", ".csv"]).path
File.open(csv_file, "w") do |fp|
fp.puts "ISBN,NOID,DOI,ID"
isbn_list.each do |isbn|
monograph_list = Monograph.where(isbn_numeric: [isbn])
if monograph_list.empty?
fp.puts "#{isbn},,,"
else
monograph = monograph_list.first
if monograph.identifier.empty?
fp.puts "#{isbn},#{monograph.id},https://doi.org/#{monograph.doi},"
else
fp.puts "#{isbn},#{monograph.id},https://doi.org/#{monograph.doi},#{monograph.identifier.first}"
end
end
end
end