-
Notifications
You must be signed in to change notification settings - Fork 3
/
listgroups.rb
60 lines (48 loc) · 1.15 KB
/
listgroups.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
require 'canvas-api'
require_relative 'connection'
require_relative 'siktfunctions'
if(ARGV.size < 3)
dbg("Usage: ruby #{$0} prod/beta gid filename")
dbg("prod/beta angir om kommandoene skal kjøres mot henholdsvis #{$prod} eller #{$beta}")
dbg("Kommandoen skrive gruppene for gruppesettet 'gid' til filename.")
exit
end
dst = ARGV[0]
gid = ARGV[1]
filename = ARGV[2]
canvas = getCanvasConnection(dst)
def OpenFile(filename)
$file = File.open( filename,"w" )
end
def CloseFile()
$file.close
end
def myputs(s)
$file << s
end
OpenFile(filename)
#["courseId", "360", "school", "1027798", "921594038"]
$firstLine = true
def processList(list)
list.each { |c|
if($firstLine)
$firstLine = false
else
myputs(",")
end
d=c["description"].split(":")
c["NSRId"] = d[3]
c["OrgNr"] =d[4]
myputs(c.to_json)
}
end
uri = sprintf("/api/v1/group_categories/%d/groups", gid)
myputs("[")
list = canvas.get(uri)
processList(list)
while list.more? do
list = list.next_page!
processList(list)
end
myputs("]")
CloseFile()