class Oddb2xml::SwissmedicDownloader
Constants
- BASE_URL
Public Class Methods
new(type = :orphan, options = {})
click to toggle source
# File lib/oddb2xml/downloader.rb, line 307 def initialize(type = :orphan, options = {}) url = BASE_URL + "/swissmedic/de/home/services/listen_neu.html" doc = Nokogiri::HTML(Oddb2xml.uri_open(url)) @type = type @options = options case @type when :orphan @direct_url_link = BASE_URL + doc.xpath("//a").find { |x| /Humanarzneimittel mit Status Orphan Drug/.match(x.children.text) }.attributes["href"].value when :package @direct_url_link = BASE_URL + doc.xpath("//a").find { |x| /Zugelassene Packungen/.match(x.children.text) }.attributes["href"].value end end
Public Instance Methods
download()
click to toggle source
# File lib/oddb2xml/downloader.rb, line 320 def download @file2save = File.join(DOWNLOADS, "swissmedic_#{@type}.xlsx") report_download(@url, @file2save) if @options[:calc] && @options[:skip_download] && File.exist?(@file2save) && ((Time.now - File.ctime(@file2save)).to_i < 24 * 60 * 60) Oddb2xml.log "SwissmedicDownloader #{__LINE__}: Skip downloading #{@file2save} #{File.size(@file2save)} bytes" return File.expand_path(@file2save) end begin @url = @direct_url_link download_as(@file2save, "w+") if @options[:artikelstamm] # ssconvert is in the package gnumeric (Debian) cmd = "ssconvert '#{@file2save}' '#{File.join(DOWNLOADS, File.basename(@file2save).sub(/\.xls.*/, ".csv"))}' 2> /dev/null" Oddb2xml.log(cmd) system(cmd) end return File.expand_path(@file2save) rescue Timeout::Error, Errno::ETIMEDOUT retrievable? ? retry : raise ensure Oddb2xml.download_finished(@file2save, false) end File.expand_path(@file2save) end