Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/fetch-categories.rb
1677 views
1
#!/usr/bin/env ruby
2
require 'json'
3
require 'net/http'
4
require 'uri'
5
require 'yaml'
6
7
# Get the list of toolcats
8
def fetch_toolcats(server)
9
uri = URI.parse(server.to_s)
10
request = Net::HTTP::Get.new(uri)
11
req_options = {
12
use_ssl: uri.scheme == 'https',
13
}
14
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
15
http.request(request)
16
end
17
18
begin
19
JSON.parse(response.body) do |w|
20
w
21
end
22
rescue StandardError
23
{}
24
end
25
end
26
27
# Parse the response
28
toolcats_eu = fetch_toolcats('https://usegalaxy-eu.github.io/usegalaxy-eu-tools/api/labels.json')
29
toolcats_org = fetch_toolcats('https://galaxyproject.github.io/usegalaxy-tools/api/labels.json')
30
toolcats_aus = fetch_toolcats('https://usegalaxy-au.github.io/usegalaxy-au-tools/api/labels.json')
31
32
tool_ids = (toolcats_org.keys + toolcats_eu.keys + toolcats_aus.keys).uniq
33
# tool_ids = toolcats_org.keys
34
tool_ids.sort!
35
36
toolcats = {}
37
# Cleanup the list
38
tool_ids.each do |k|
39
eu = toolcats_eu[k] || nil
40
org = toolcats_org[k] || nil
41
aus = toolcats_aus[k] || nil
42
43
# We get N 'votes' for the categories
44
values = [eu, org, aus].compact
45
# values = [org].compact
46
47
# Majority answer wins
48
# set that value to toolcats[k]
49
# If there is no majority, pick one.
50
# print("#{k} - #{values.length} => #{values.uniq.compact.length}\n")
51
toolcats[k] = (values.max_by { |v| v['count'] } if values.length.positive?)
52
end
53
54
# Write the list to a file
55
File.write('metadata/toolcats.yml', toolcats.to_yaml)
56
57