Skip to content

Commit

Permalink
Add .rubocop config and fix ig_download script
Browse files Browse the repository at this point in the history
  • Loading branch information
projkov committed Apr 18, 2024
1 parent 0cdbdb4 commit b73e6fa
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 30 deletions.
42 changes: 42 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
AllCops:
Exclude:
- 'worker.rb'
- 'spec/au_core/search_test_spec.rb'
- 'lib/au_core_test_kit/search_test.rb'
- 'lib/au_core_test_kit/search_test_properties.rb'
- 'spec/spec_helper.rb'
- 'spec/au_core/provenance_validator_spec.rb'
- 'spec/au_core/must_support_test_spec.rb'
- 'spec/au_core/generator/must_support_metadata_extractor_spec.rb'
- 'spec/au_core/date_search_validation_test_spec.rb'
- 'lib/au_core_test_kit/validation_test.rb'
- 'lib/au_core_test_kit/request_logger.rb'
- 'lib/au_core_test_kit/reference_resolution_test.rb'
- 'lib/au_core_test_kit/read_test.rb'
- 'lib/au_core_test_kit/provenance_validator.rb'
- 'lib/au_core_test_kit/must_support_test.rb'
- 'lib/au_core_test_kit/helpers.rb'
- 'lib/au_core_test_kit/generator/value_extractor.rb'
- 'lib/au_core_test_kit/generator/validation_test_generator.rb'
- 'lib/au_core_test_kit/generator/terminology_binding_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/summary_generator.rb'
- 'lib/au_core_test_kit/generated/**/*'
- 'lib/au_core_test_kit/generator/search_test_generator.rb'
- 'lib/au_core_test_kit/generator/search_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/search_definition_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/must_support_test_generator.rb'
- 'lib/au_core_test_kit/custom_groups/**/*'
- 'lib/au_core_test_kit/date_search_validation.rb'
- 'lib/au_core_test_kit/fhir_resource_navigation.rb'
- 'lib/au_core_test_kit/generator/provenance_revinclude_search_test_generator.rb'
- 'lib/au_core_test_kit/generator/must_support_metadata_extractor_au_core_3.rb'
- 'lib/au_core_test_kit/generator/must_support_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/ig_resources.rb'
- 'lib/au_core_test_kit/generator/ig_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/ig_loader.rb'
- 'lib/au_core_test_kit/generator/group_metadata_extractor.rb'
- 'lib/au_core_test_kit/generator/group_generator.rb'
- 'lib/au_core_test_kit/generator/group_metadata.rb'
- 'lib/au_core_test_kit/generator.rb'
Style/Documentation:
Enabled: false
68 changes: 38 additions & 30 deletions lib/au_core_test_kit/generator/ig_download.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
# frozen_string_literal: true

require 'nokogiri'
require 'open-uri'
require 'uri'
require 'json'
require 'net/http'

url = 'http://hl7.org.au/fhir/core/history.html'

html_content = URI.open(url).read
begin
uri = URI.parse(url)
response = Net::HTTP.get_response(uri)

doc = Nokogiri::HTML(html_content)
unless response.is_a?(Net::HTTPSuccess)
puts "Failed to fetch HTML content from #{url}. HTTP Status: #{response.code} #{response.message}"
exit
end

html_content = response.body

doc = Nokogiri::HTML(html_content)

script_tag = doc.at('script:contains("var pageJSON")')
script_tag = doc.at('script:contains("var pageJSON")')

ig_versions_to_skip = ['0.1.0-draft', '0.2.0-preview', '0.2.1-preview', '0.2.2-preview']
ig_versions_to_skip = ['0.1.0-draft', '0.2.0-preview', '0.2.1-preview', '0.2.2-preview']

if script_tag&.content
json_data = script_tag.content[/\{.*\}/m]
if json_data
data_hash = JSON.parse(json_data)
data_hash['list'].each do |item|
version = item['version']
next if ig_versions_to_skip.include? version
if script_tag&.content
json_data = script_tag.content[/\{.*\}/m]
if json_data
data_hash = JSON.parse(json_data)
data_hash['list'].each do |item|
version = item['version']
next if ig_versions_to_skip.include? version

package_url = "#{item['path']}/package.tgz"
file_name = "#{version}.tgz"
output_directory = 'lib/au_core_test_kit/igs'
package_url = "#{item['path']}/package.tgz"
file_name = "#{version}.tgz"
output_directory = 'lib/au_core_test_kit/igs'

Dir.mkdir(output_directory) unless File.directory?(output_directory)
Dir.mkdir(output_directory) unless File.directory?(output_directory)

File.open(File.join(output_directory, file_name), 'wb') do |file|
uri = URI.parse(package_url)
response = Net::HTTP.get_response(uri)
if response.is_a?(Net::HTTPSuccess)
file.write(response.body)
puts "Successfully downloaded #{file_name}"
else
puts "Failed to download #{file_name}. HTTP Status: #{response.code} #{response.message}"
File.open(File.join(output_directory, file_name), 'wb') do |file|
uri = URI.parse(package_url)
response = Net::HTTP.get_response(uri)
if response.is_a?(Net::HTTPSuccess)
file.write(response.body)
puts "Successfully downloaded #{file_name}"
else
puts "Failed to download #{file_name}. HTTP Status: #{response.code} #{response.message}"
end
end
rescue StandardError => e
puts "An error occurred while downloading #{file_name}: #{e.message}"
end
else
puts 'Error: Unable to extract JSON data from script tag.'
end
else
puts 'Error: Unable to extract JSON data from script tag.'
puts 'Error: Script tag containing pageJSON variable not found.'
end
else
puts 'Error: Script tag containing pageJSON variable not found.'
rescue StandardError => e
puts "An error occurred: #{e.message}"
end

0 comments on commit b73e6fa

Please sign in to comment.