Class: Oddb2xml::SwissmedicDownloader
- Inherits:
-
Downloader
- Object
- Downloader
- Oddb2xml::SwissmedicDownloader
- Defined in:
- lib/oddb2xml/downloader.rb
Instance Attribute Summary
Attributes inherited from Downloader
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(type = :orphan, options = {}) ⇒ SwissmedicDownloader
constructor
A new instance of SwissmedicDownloader.
Methods inherited from Downloader
Constructor Details
#initialize(type = :orphan, options = {}) ⇒ SwissmedicDownloader
Returns a new instance of SwissmedicDownloader.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/oddb2xml/downloader.rb', line 256 def initialize(type=:orphan, = {}) @type = type @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 action = "arzneimittel/00156/00221/00222/00235/index.html?lang=de" @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 = "https://www.swissmedic.ch/#{action}" super(@options, url) end |
Instance Method Details
#download ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/oddb2xml/downloader.rb', line 273 def download @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.(file) end begin FileUtils.rm(File.(file), :verbose => !defined?(RSpec)) if File.exists?(File.(file)) page = @agent.get(@url) if !page.class.is_a?(String) and link_node = page.search(@xpath).first link = Mechanize::Page::Link.new(link_node, @agent, page) response = link.click response.save_as(file) response = nil # win end return File.(file) rescue Timeout::Error, Errno::ETIMEDOUT retrievable? ? retry : raise ensure Oddb2xml.download_finished(file, false) end return File.(file) end |