-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpress_list
78 lines (65 loc) · 2.12 KB
/
press_list
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script displays a list of press monographs
require 'optparse'
require 'ostruct'
require 'os'
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
root_dir = File.dirname(script_dir)
require_relative File.join(root_dir, "lib", "logger")
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
# Process the script parameters.
options = OpenStruct.new
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} press [press..]"
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(opts)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 1
script_logger.info(option_parser.help)
return
end
press_list = ARGV
#require_relative File.join(root_dir, 'lib', 'services')
require_relative File.join(root_dir, 'lib', 'fulcrum')
# Create the serivce for retrieving the NOID.
service = UMPTG::Services::Heliotrope.new(
:fulcrum_host => options.fulcrum_host
)
monographs_list = service.monographs(press_list: press_list)
noid_list = []
monographs_list.each do |monograph|
noid = monograph["id"]
manifest = UMPTG::Fulcrum::Manifest::Document.new(
monograph_id: noid
)
isbn = manifest.isbn['open access'] if manifest.isbn.key?('open access')
isbn = manifest.isbn['ebook'] if isbn.nil?
isbn = manifest.isbn['oa ebook'] if isbn.nil?
isbn = manifest.isbn['epub'] if isbn.nil?
isbn = manifest.isbn['pdf'] if isbn.nil?
if isbn.nil?
script_logger.error("no ISBN for #{noid}")
next
end
doi = manifest.monograph_row['doi']
if doi.nil?
script_logger.error("no DOI for #{noid}")
next
end
noid_list << "#{noid},#{isbn},#{doi.strip.delete_prefix("https://doi.org/")},#{manifest.monograph_row['link'][12..-3]}"
next
nlist = service.monograph_noid(identifier: isbn)
STDOUT.flush
next unless nlist.count == 1
noid_list << noid
#rep_list = manifest.representatives()
#next if rep_list.key?('pdf_ebook')
#puts noid
#STDOUT.flush
end
File.write("xref_list.tsv", noid_list.join("\n"))