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

- old
+ new

@@ -254,12 +254,13 @@ end xml end end class SwissmedicDownloader < Downloader - def initialize(type=:orphan) + def initialize(type=:orphan, options = {}) @type = type + @options = options case @type when :orphan action = "arzneimittel/00156/00221/00222/00223/00224/00227/00228/index.html?lang=de" @xpath = "//div[@id='sprungmarke10_3']//a[@title='Humanarzneimittel']" when :fridge @@ -267,15 +268,20 @@ @xpath = "//div[@id='sprungmarke10_2']//a[@title='Excel-Version']" when :package action = "arzneimittel/00156/00221/00222/00230/index.html?lang=de" @xpath = "//div[@id='sprungmarke10_7']//a[@title='Excel-Version Zugelassene Verpackungen*']" end - url = "http://www.swissmedic.ch/#{action}" - super({}, url) + url = "https://www.swissmedic.ch/#{action}" + super(@options, url) end def download - @type == file = "swissmedic_#{@type}.xlsx" + @type == file = File.join(Oddb2xml::WorkDir, "swissmedic_#{@type}.xlsx") + if @options[:calc] and @options[:skip_download] and File.exists?(file) and (Time.now-File.ctime(file)).to_i < 24*60*60 + Oddb2xml.log "SwissmedicDownloader #{__LINE__}: Skip downloading #{file} #{File.size(file)} bytes" + return File.expand_path(file) + end begin + FileUtils.rm(File.expand_path(file), :verbose => true) if File.exists?(File.expand_path(file)) page = @agent.get(@url) if link_node = page.search(@xpath).first link = Mechanize::Page::Link.new(link_node, @agent, page) response = link.click response.save_as(file)