Sha256: a1df124d882d3527da2ad19247d31af8639da43893633d41d83fed50faca58ec

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require_relative 'lib/bipm-data-importer'

a = Mechanize.new

meetings_en = VCR.use_cassette 'cgpm-meetings' do
  a.get "https://www.bipm.org/en/worldwide-metrology/cgpm/resolutions.html"
end

meetings_fr = VCR.use_cassette 'cgpm-meetings-fr' do
  a.get "https://www.bipm.org/fr/worldwide-metrology/cgpm/resolutions.html"
end

FileUtils.rm_rf "cgpm/meetings"
FileUtils.rm_rf "cgpm/meetings-fr"
FileUtils.rm_rf "cgpm/meetings-en"

(meetings_en.css('select[name="cgpm_value"] option') +
 meetings_fr.css('select[name="cgpm_value"] option')).each do |option|

  url = option.attr('value')
  next unless url

  meeting_id = url.split('/').last.to_i
  meeting_lang = url.split('/')[1]
  meeting_lang_sfx     = (meeting_lang == 'fr') ? "-fr" : ""
  meeting_lang_sfx_dir = (meeting_lang == 'fr') ? "-fr" : "-en"
  meeting = VCR.use_cassette("cgpm-meeting-#{meeting_id}#{meeting_lang_sfx}") { a.get url }

  title_part = meeting.at_css('.GrosTitre').text.chomp
  title, date = title_part.split(" (")
  date = date.split("-").last.gsub("juin", "june")
  date = Date.parse(date) # NB: 13-16 November 2018 -> 2018-11-16

  binding.pry if date <= Date.parse("0000-01-01") || date >= Date.today

  h = {
    "metadata" => {
      "title" => title,
      "date" => date,
      "source" => "BIPM - Pavillon de Breteuil",
      "url" => meeting.uri.to_s
    }
  }

  h["resolutions"] = meeting.links_with(class: "introGras").map do |res_link|
    res_id = res_link.href.split('/')[-1].to_i
    res = VCR.use_cassette("cgpm-resolution-#{meeting_id}-#{res_id}#{meeting_lang_sfx}") { res_link.click }

    Bipm::Data::Importer::Common.parse_resolution(res, res_id, date, :cgpm)
  end

  FileUtils.mkdir_p("cgpm/meetings#{meeting_lang_sfx_dir}")
  File.write("cgpm/meetings#{meeting_lang_sfx_dir}/meeting-#{"%02d" % meeting_id}.yml", YAML.dump(h))
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bipm-data-importer-0.1.1 exe/bipm-fetch-cgpm