lib/oddb2xml/cli.rb in oddb2xml-1.9.4 vs lib/oddb2xml/cli.rb in oddb2xml-1.9.5

- old
+ new

@@ -6,10 +6,11 @@ require 'oddb2xml/extractor' require 'oddb2xml/compressor' require 'oddb2xml/options' require 'oddb2xml/util' require 'rubyXL' +require 'date' # for today module Oddb2xml class Cli SUBJECTS = %w[product article] @@ -40,11 +41,13 @@ end @_message = false end def run threads = [] - if @options[:address] + if @options[:calc] + threads << download(:package) # swissmedic + elsif @options[:address] [:company, :person].each do |type| threads << download(type) # medregbm.admin end else if @options[:format] != :dat @@ -89,13 +92,17 @@ end private def build Oddb2xml.log("Start build") begin + @_files = {"calc"=>"oddb_calc.xml"} if @options[:calc] files.each_pair do |sbj, file| builder = Builder.new(@options) do |builder| - if @options[:address] + if @options[:calc] + builder.packs = @packs + builder.subject = sbj + elsif @options[:address] builder.subject = sbj builder.companies = @companies builder.people = @people else # product if @options[:format] != :dat @@ -141,10 +148,13 @@ end else output = builder.to_xml end File.open(File.join(WorkDir, file), 'w:utf-8'){ |fh| fh << output } + if @options[:calc] + FileUtils.cp(File.join(WorkDir, file), File.join(WorkDir, file.sub('.xml', '_'+Time.now.strftime("%d.%m.%Y_%H.%M")+'.xml')), :verbose => true) + end end rescue Interrupt files.values.each do |file| if File.exist? file File.unlink(file) # we don't save it as it might be only partly downloaded @@ -204,16 +214,17 @@ Oddb2xml.log("MigelExtractor added #{@migel.size} migel items") end end when :package Thread.new do - downloader = SwissmedicDownloader.new(:package) + downloader = SwissmedicDownloader.new(:package, @options) bin = downloader.download @mutex.synchronize do @packs = SwissmedicExtractor.new(bin, :package).to_hash -# Oddb2xml.log("SwissmedicExtractor added #{@packs.size} packs. File #{bin} was #{File.size(bin)} bytes") - end + Oddb2xml.log("SwissmedicExtractor added #{@packs.size} packs from #{bin}") + @packs + end unless @options[:calc] end when :bm_update Thread.new do downloader = BMUpdateDownloader.new str = downloader.download @@ -294,13 +305,13 @@ @_files[:dat] = "#{prefix}_with_migel.dat" end else # xml ## # building order - # 1. addtions + # 1. additions # 2. subjects - # 3. optionals + # 3. optional SUBJECTS _files = (ADDITIONS + SUBJECTS) _files += OPTIONALS if @options[:fi] _files.each do|sbj| @_files[sbj] = "#{prefix}_#{sbj.to_s}.xml" end @@ -311,9 +322,14 @@ def prefix @_prefix ||= (@options[:tag_suffix] || 'oddb').gsub(/^_|_$/, '').downcase end def report lines = [] + if @options[:calc] + lines << Calc.dump_new_galenic_forms + lines << Calc.dump_names_without_galenic_forms + lines << Calc.report_conversion + end unless @options[:address] LANGUAGES.each do |lang| lines << lang types.each do |type| if @index[lang][type]