lib/relaton_bipm/data_fetcher.rb in relaton-bipm-1.12.3 vs lib/relaton_bipm/data_fetcher.rb in relaton-bipm-1.13.0
- old
+ new
@@ -55,11 +55,17 @@
#
# Parse SI brochure and write them to YAML files
#
def parse_si_brochure # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
+ # puts "Parsing SI brochure..."
+ # puts "Ls #{Dir['*']}"
+ # puts "Ls #{Dir['bipm-si-brochure/*']}"
+ # puts "Ls #{Dir['bipm-si-brochure/site/*']}"
+ # puts "Ls #{Dir['bipm-si-brochure/site/documents/*']}"
Dir["bipm-si-brochure/site/documents/*.rxl"].each do |f|
+ puts "Parsing #{f}"
docstd = Nokogiri::XML File.read f
doc = docstd.at "/bibdata"
hash1 = RelatonBipm::XMLParser.from_xml(doc.to_xml).to_hash
hash1["fetched"] = Date.today.to_s
hash1["docid"].detect { |id| id["type"] == "BIPM" }["primary"] = true
@@ -73,10 +79,11 @@
warn_duplicate = true
hash1
end
item = RelatonBipm::BipmBibliographicItem.from_hash(**hash)
write_file outfile, item, warn_duplicate: warn_duplicate
+ puts "Saved to #{outfile}"
end
end
#
# Deep merge two hashes
@@ -115,13 +122,13 @@
# @param [String] body name of body
#
def fetch_type(dir, body) # rubocop:disable Metrics/AbcSize
type = dir.split("/").last.split("-").first.sub(/s$/, "")
body_dir = File.join @output, body.downcase
- Dir.mkdir body_dir unless Dir.exist? body_dir
+ FileUtils.mkdir_p body_dir
outdir = File.join body_dir, type.downcase
- Dir.mkdir outdir unless Dir.exist? outdir
+ FileUtils.mkdir_p outdir
Dir[File.join(dir, "*.{yml,yaml}")].each { |en_file| fetch_meeting en_file, body, type, outdir }
end
#
# Create and write BIPM meeting/resolution
@@ -226,10 +233,10 @@
item = RelatonBipm::BipmBibliographicItem.new(**hash)
file = year
file += "-#{num_justed}" if num.size < 4
file += ".yaml"
out_dir = File.join args[:dir], r["type"].downcase
- Dir.mkdir out_dir unless Dir.exist? out_dir
+ FileUtils.mkdir_p out_dir
path = File.join out_dir, file
write_file path, item
@index[["#{args[:body]} #{type} #{year}-#{num_justed}", "#{args[:body]} #{type} #{args[:num]}-#{num_justed}"]] = path
end
end