-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate_recording_list.rb
executable file
·119 lines (106 loc) · 3.72 KB
/
generate_recording_list.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/ruby
require 'adobe_connect'
require 'date'
require 'csv'
def output_data(connect,sco_id)
response = connect.sco_info(sco_id: sco_id)
folder_id = response.at_xpath('//sco//@folder-id')
folder_response = connect.sco_info(sco_id: folder_id)
folder_name = folder_response.at_xpath('//sco//name').text
line = Array.new()
line.push(sco_id)
line.push(folder_name.tr(',', '').tr('(','').tr(')',''))
line.push(response.at_xpath('//sco//name').text.tr(',', '').tr('(','').tr(')',''))
# if the recording has a description available through the API- add it to the CSV
if response.at_xpath('//sco//description')
line.push(response.at_xpath('//sco//description').text.tr(',', '').tr('(','').tr(')','').gsub("\n",'<BR>'))
else
# we want to maintain the same amount of values in each line array
line.push('')
end
line.push(response.at_xpath('//sco//url-path').text.tr('/', ''))
line.push(DateTime.parse(response.at_xpath('//sco/date-created').text).to_time.to_i.to_s)
found_user = false
if $user_mapping
for row in $user_mapping do
if row[0] == sco_id
line.push(row[1], '', '')
found_user = true
break
end
end
else
url_path = response.at_xpath('//sco//url-path').text.tr('/', '')
owner_info = connect.sco_by_url(url_path: url_path)
if owner_info.at_xpath('//owner-principal')
found_user = true
line.push(owner_info.at_xpath('//owner-principal//email') ? owner_info.at_xpath('//owner-principal//email').text : '')
line.push(owner_info.at_xpath('//owner-principal//login') ? owner_info.at_xpath('//owner-principal//login').text : '')
line.push(owner_info.at_xpath('//owner-principal//name') ? owner_info.at_xpath('//owner-principal//name').text : '')
end
end
if !found_user
line.push('','','')
end
# Calculate the duration if available
found_duration = false
if $duration_mapping
for row in $duration_mapping do
if row[0] == sco_id
line.push(row[1].to_f*60)
found_duration = true
break
end
end
end
if !found_duration
duration_xpath = '//sco/duration'
start_date_xpath = '//sco/date-begin'
end_date_xpath = '//sco/date-end'
if response.at_xpath(duration_xpath)
line.push(response.at_xpath(duration_xpath).text)
elsif response.at_xpath(start_date_xpath) && response.at_xpath(end_date_xpath)
startTime = DateTime.parse(response.at_xpath(start_date_xpath).text).to_time.to_i
endTime = DateTime.parse(response.at_xpath(end_date_xpath).text).to_time.to_i
duration = endTime - startTime
line.push(duration.to_s)
else
line.push('')
end
end
# format line into CSV string and print it out.
csv_line_string = line.to_csv()
print csv_line_string
end
if ARGV.length < 1
puts 'Usage: ' + __FILE__ + ' </path/to/sco/list>'
exit 1
end
if (!File.exist?(ARGV[0]))
puts 'File ' + ARGV[0] + ' does not exist.'
exit 1
end
# start by configuring it with a username, password, and domain.
AdobeConnect::Config.declare do
username ENV['AC_USERNAME']
password ENV['AC_PASSWD']
domain ENV['AC_ENDPOINT']
end
connect = AdobeConnect::Service.new
# log in so you have a session
connect.log_in #=> true
$user_mapping = nil
if ENV['SCOID_USER_MAPPING'] && File.file?(ENV['SCOID_USER_MAPPING'])
# slurp file into array of arrays
$user_mapping = CSV.read(ENV['SCOID_USER_MAPPING'])
end
$duration_mapping = nil
if ENV['SCOID_DURATION_MAPPING'] && File.file?(ENV['SCOID_DURATION_MAPPING'])
# slurp file into array of arrays
$duration_mapping = CSV.read(ENV['SCOID_DURATION_MAPPING'])
end
text = File.open(ARGV[0]).read
text.gsub!(/\r\n?/, '')
text.each_line do |line|
output_data(connect, line.delete!("\n"))
end