-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngs_registry_scraper.rb
68 lines (54 loc) · 1.98 KB
/
ngs_registry_scraper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
require 'tess_uploader'
$lessons = {}
$debug = false
$json_file = 'https://bioinformatics.upsc.se/trainers/details.json'
$owner_org = 'ngs_registry'
$topics = {}
$root_url = 'https://microasp.upsc.se/ngs_trainers/Materials/tree/master/'
$lessons = JSON.parse(open($json_file).read)
# Create the organisation.
org_title = 'NGS Registry'
org_name = $owner_org
org_desc = 'GitLab registry containing NGS Training Materials'
org_image_url = ''
homepage = 'https://microasp.upsc.se/ngs_trainers/Materials/wikis/home'
node_id = ''
organisation = Organisation.new(org_title,org_name,org_desc,org_image_url,homepage,node_id)
Uploader.check_create_organisation(organisation)
# do the uploads
$lessons.each do |lesson|
material = lesson[1]
relative_path = lesson[0]
course = Tuition::Tutorial.new
course.url = $root_url + relative_path
course.owner_org = $owner_org
course.title = material['title']
course.set_name($owner_org,material['title'])
if material['full'].nil?
course.description = material['title']
course.notes = "#{material['title']} from #{$root_url + key}, added automatically."
else
description = material['full']
sections = ["## Keywords\n", "## Target audience (at least beginner/advanced)\n"]
keywords_index = description.find_index(sections[0])
if !keywords_index.nil?
puts description[keywords_index+1]
a = description[keywords_index+1].split(',').map{|t| {'name' => t}}
course.tags = a
end
audience_index = description.find_index(sections[1])
if !audience_index.nil?
course.audience = description[audience_index+2]
end
course.description = description.join('')
course.notes = material['full'].join('')
end
course.format = 'html'
# Before attempting to create anything we need to check if the resource/dataset already exists, updating it
# as and where necessary.
Uploader.create_or_update(course)
#print "Course: #{course.dump}\n\n\n\n\n"
end