dcav-stats/gen_index.rb
2017-05-09 00:07:59 +02:00

42 lines
847 B
Ruby

require 'erb'
require 'filesize'
erb_file = "dcav-index.erb"
html_file = "/var/shots/html/index.html"
class User
attr_accessor :name, :count, :size
def <=> (other)
other.count <=> count
end
end
RES_BASE = "https://strawberry.thedevcave.net/~christoffermadsen/"
usernames = ["christoffermadsen","jmaa","jacob","alexander"]
users = []
shot_dir = "/var/shots/"
usernames.each do |username|
user = User.new
user.name = username
size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1`
count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1`
[size,count].each do |x|
x.delete! "\n"
end
user.size = size.to_i
user.count = count.to_i
users << user
end
output = ERB.new(File.read(erb_file)).result
puts output
File.open(html_file, 'w') do |f|
f.write(output)
end