Path: blob/main/bin/fetch-categories.rb
1677 views
#!/usr/bin/env ruby1require 'json'2require 'net/http'3require 'uri'4require 'yaml'56# Get the list of toolcats7def fetch_toolcats(server)8uri = URI.parse(server.to_s)9request = Net::HTTP::Get.new(uri)10req_options = {11use_ssl: uri.scheme == 'https',12}13response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|14http.request(request)15end1617begin18JSON.parse(response.body) do |w|19w20end21rescue StandardError22{}23end24end2526# Parse the response27toolcats_eu = fetch_toolcats('https://usegalaxy-eu.github.io/usegalaxy-eu-tools/api/labels.json')28toolcats_org = fetch_toolcats('https://galaxyproject.github.io/usegalaxy-tools/api/labels.json')29toolcats_aus = fetch_toolcats('https://usegalaxy-au.github.io/usegalaxy-au-tools/api/labels.json')3031tool_ids = (toolcats_org.keys + toolcats_eu.keys + toolcats_aus.keys).uniq32# tool_ids = toolcats_org.keys33tool_ids.sort!3435toolcats = {}36# Cleanup the list37tool_ids.each do |k|38eu = toolcats_eu[k] || nil39org = toolcats_org[k] || nil40aus = toolcats_aus[k] || nil4142# We get N 'votes' for the categories43values = [eu, org, aus].compact44# values = [org].compact4546# Majority answer wins47# set that value to toolcats[k]48# If there is no majority, pick one.49# print("#{k} - #{values.length} => #{values.uniq.compact.length}\n")50toolcats[k] = (values.max_by { |v| v['count'] } if values.length.positive?)51end5253# Write the list to a file54File.write('metadata/toolcats.yml', toolcats.to_yaml)555657