-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathlist_files_per_project.rb
42 lines (31 loc) · 1.1 KB
/
list_files_per_project.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
require 'looker-sdk'
# get API creds from environment variables
sdk = LookerSDK::Client.new(
:client_id => ENV['LOOKERSDK_CLIENT_ID'],
:client_secret => ENV['LOOKERSDK_CLIENT_SECRET'],
:api_endpoint => ENV['LOOKERSDK_BASE_URL']
)
overall_file_types = Array.new
all_projects = sdk.all_projects(:fields => 'id')
# iterate through all projects
all_projects.each { |project|
file_types = Array.new
puts "\n"
puts "*"*60
puts "Project: #{project[:id]}"
project_files_list = sdk.all_project_files(project[:id], :fields => 'id, type, path')
project_files_list.each { |file|
# add the type to the array to count later on
file_types.push(file[:type])
overall_file_types.push(file[:type])
}
# get a count of each individual value in the array
file_types_counted = file_types.group_by{|e| e}.map{|k, v| [k, v.length]}.to_h
puts file_types_counted.map{ |k,v| "#{k} => #{v}" }.sort.reverse
}
puts "\n"
puts "*"*60
puts "SUMMARY: "
all_types_counted = overall_file_types.group_by{|e| e}.map{|k, v| [k, v.length]}.to_h
puts all_types_counted.map{ |k,v| "#{k} => #{v}" }.sort.reverse
puts "*"*60