-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget-unsupported-downloaders.rb
executable file
·61 lines (50 loc) · 1.39 KB
/
get-unsupported-downloaders.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
#!/usr/bin/env script/rails runner
require 'download_helper'
begin
if ARGV.count != 1
puts "Please provide filename for out of csv file!"
exit
end
filename = ARGV[0]
list = {}
betas_with_downloads = DownloadHelper.find_betas_with_downloads()
betas_with_downloads.each do |b|
b[:users_with_downloads].each do |u|
if !u.employee?
# Mark that support has been requested
u.participations.where("beta_id = ?",b[:beta].id).each do |p|
if p.support_req.blank?
# Add hash with selected beta into hash, which contains user
# information
list[u.id] ||= {}
list[u.id][:betas] ||= []
list[u.id][:betas] << b[:beta].alias
p.support_req = true
p.save!
end
end
end # u.external?
end
end
body = ""
header = "ID,email,alt_email,Name,login,Betas,Company\n"
list.keys.sort.uniq.each do |k|
u = User.find(k)
body += "#{u.id}"
body += ",#{u.email}"
body += ",#{u.alt_email}"
body += ",#{u.full_name}"
body += ",#{u.login_name}"
body += ",\"#{list[u.id][:betas].uniq.join(',')}\""
company = ","
company += u.company.name if !u.company.blank?
body += company
body += "\n"
end
puts body
# Write csv file
File.open( filename, 'w') do |f|
f.write header
f.write body
end
end