-
Notifications
You must be signed in to change notification settings - Fork 3
/
UUcheckcourse.rb
64 lines (55 loc) · 1.45 KB
/
UUcheckcourse.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
require 'canvas-api'
require 'colorize'
require_relative 'connection'
require_relative 'siktfunctions'
dst = ARGV[0]
$cid = ARGV[1]
s = ARGV[2]
if(ARGV.size < 1)
dbg("Usage: ruby #{$0} run")
dbg("Søker etter innhold i mappen.")
exit
end
$discussionType = 0
$assignmentType = 1
$quizType = 2
$pageType = 3
$canvas = getCanvasConnection(dst)
dbg($canvas)
def containsSubtitles(url)
buffer = open(url).read
if(buffer.include? "<error>")
return false
end
return true
end
puts "UU-kontroll"
puts "Sjekker innholdssider for vimeofilmer og underteksting"
i=0
kpasVideoUrls = []
Dir.foreach('.') do |filename|
next if filename == '.' or filename == '..'
# Do work on the remaining files & directories
#puts filename
i=i+1
buffer = open(filename).read
result = JSON.parse(buffer)
html_url = result["html_url"]
course_id = result["course_id"]
urls = URI.extract(result["body"], /http(s)?/)
urls.each do |url|
match = url.match(/https?:\/\/(?:[\w]+\.)*vimeo\.com(?:[\/\w]*\/?)?\/(?<id>[0-9]+)[^\s]*/)
if(match)
id = match[:id]
kpasurl = "https://kpas-lti.azurewebsites.net/api/vimeo/#{id}"
if(!containsSubtitles(kpasurl))
puts("Mangler underteksting i URL:#{html_url} VIMEOURL:#{url} SUBTITLESURL:#{kpasurl}")
kpasVideoUrls.push(id)
end
end
end
end
puts "No of files:#{i}"
kpasVideoUrls.each do |videoId|
puts 'delete from subtitles where videoId="' + videoId +'";'
end