This repository was archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindit_data.rb
More file actions
65 lines (55 loc) · 2.39 KB
/
findit_data.rb
File metadata and controls
65 lines (55 loc) · 2.39 KB
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
# Check the arguments
require './lib/delete'
require './lib/fetch'
require './lib/index'
require './lib/record_providers'
include FindItData
def print_usage_tips
puts "Usage: ruby findit_data.rb -fi oclc"
puts
puts "-d will remove the records from solr"
puts "-f will fetch the records from the record provider"
puts "-i will index the records in solr; you can pass a file to this option to index a field you've already downloaded (e.g. ruby findit_data.rb -i opentextbooks file.mrc)"
puts "-r will do all of the above, resulting in a re-index"
puts
puts "List of record providers"
FindItData::record_providers.each do |provider, details|
puts provider
end
abort
end
if (2 > ARGV.size) or (3 < ARGV.size)
print_usage_tips
end
unless ARGV[0].include? '-'
print_usage_tips
end
if ARGV[0].include? 'd' or ARGV[0].include? 'r'
puts "Deleting all that stuff"
FindItData::delete_by_query 'record_provider_facet', FindItData::record_providers[ARGV[1]]['record_provider_facet']
end
if ARGV[0].include? 'f' or ARGV[0].include? 'r'
Dir.mkdir 'new' unless File.exists? 'new'
Dir.mkdir 'update' unless File.exists? 'update'
Dir.mkdir 'delete' unless File.exists? 'delete'
puts "Fetching the file"
if FindItData::record_providers.include? ARGV[1]
if 'http' == FindItData::record_providers[ARGV[1]]['fetch_method']
if FindItData::record_providers[ARGV[1]].key? 'fetch_opts'
file_names = FindItData::fetch_http FindItData::record_providers[ARGV[1]]['fetch_url'], FindItData::record_providers[ARGV[1]]['file_prefix'], FindItData::record_providers[ARGV[1]]['fetch_opts']
else
file_names = FindItData::fetch_http FindItData::record_providers[ARGV[1]]['fetch_url'], FindItData::record_providers[ARGV[1]]['file_prefix']
end
elsif 'ftp' == FindItData::record_providers[ARGV[1]]['fetch_method']
file_names = FindItData::fetch_ftp FindItData::record_providers[ARGV[1]]['remote_server'], FindItData::record_providers[ARGV[1]]['file_prefix'], FindItData::record_providers[ARGV[1]]['credentials']
end
else
print_usage_tips
end
end
if ARGV[0].include? 'i' or ARGV[0].include? 'r'
if file_names.nil?
file_names = Array(ARGV[2])
end
FindItData::index file_names, FindItData::record_providers[ARGV[1]]['traject_configuration_files']
end