Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/google-form-recordings.rb
1677 views
1
#!/usr/bin/env ruby
2
# frozen_string_literal: true
3
4
require 'yaml'
5
require 'net/http'
6
require 'csv'
7
require 'date'
8
require './_plugins/util'
9
10
# Fetch data from a google sheet
11
url = 'https://docs.google.com/spreadsheets/d/1iXjLlMEH5QMAMyUMHi1c_Lb7OiJhL_9hgJrtAsBoZ-Y/export?format=tsv'
12
data = `curl -sL "#{url}"`
13
new_recordings = false
14
15
data = CSV.parse(data, col_sep: "\t", headers: true, quote_char: '|')
16
count = 0
17
18
# define some columns
19
col_material = 3
20
col_length = 5
21
col_speakers = 6
22
col_galaxyversion = 10
23
col_prmade = 12
24
25
## recordings metadata definition on tutorials/slides
26
#
27
# recordings:
28
# - speakers:
29
# - shiltemann
30
# captioners:
31
# - hexylena
32
# - bebatut
33
# date: '2020-06-12'
34
# galaxy_version: '20.05'
35
# length: 51M
36
# youtube_id: "oAVjF_7ensg"
37
38
data.each do |row|
39
# Parse
40
# 29/01/2024 14:04:47
41
submission_date = DateTime.strptime(row['Timestamp'], '%d/%m/%Y %H:%M:%S')
42
43
# extract metadata from Google form
44
length = row[col_length]
45
galaxy_version= row[col_galaxyversion]
46
speakers = row[col_speakers]&.split(",")
47
date = submission_date.strftime('%Y-%m-%d')
48
49
if row[col_material] == 'TESTING' or row[col_prmade] == 'yes'
50
STDERR.puts "Skipping recording as it is a test or a PR was already openened"
51
next
52
end
53
54
material_file = row[col_material].gsub("tutorial.html","tutorial.md").gsub("https://training.galaxyproject.org/","").gsub("training-material/","").gsub("training-material//","")
55
56
57
bot_timestamp = submission_date.to_time.to_i
58
recording_metadata = {"youtube_id" => "TODO",
59
"length" => length,
60
"galaxy_version" => galaxy_version,
61
"date" => date,
62
"speakers" => speakers,
63
"captioners" => speakers.dup,
64
"bot-timestamp" => bot_timestamp }
65
66
# append metadata into GTN material
67
material_metadata = safe_load_yaml(material_file)
68
69
if material_metadata["recordings"]
70
# check the "bot_timestamp"
71
exists = false
72
for rec in material_metadata["recordings"]
73
if rec["bot-timestamp"].to_s == bot_timestamp.to_s
74
exists = true
75
end
76
end
77
78
if !exists
79
material_metadata["recordings"].push(recording_metadata)
80
new_recordings = true
81
end
82
else
83
material_metadata["recordings"] = [recording_metadata]
84
new_recordings = true
85
end
86
87
#pp material_metadata
88
89
# write to file
90
material_original = File.open(material_file,"r").read.split("---\n",3)
91
92
outfile = File.open(material_file,"w")
93
outfile.write("#{material_metadata.to_yaml}\n\n---\n\n#{material_original[2]}")
94
95
end
96
97
STDERR.puts "new recordings: #{new_recordings}"
98
puts new_recordings
99
100