From ef66639f8372c91a0392dbf1dc289e6af9afd579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoffer=20M=C3=BCller=20Madsen?= Date: Tue, 9 May 2017 00:07:59 +0200 Subject: [PATCH] rename and update index page generator --- dcav-index.erb | 42 ++++++++++++++++++++++++++++++++++++++++++ gen_index.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 dcav-index.erb create mode 100644 gen_index.rb diff --git a/dcav-index.erb b/dcav-index.erb new file mode 100644 index 0000000..84df94a --- /dev/null +++ b/dcav-index.erb @@ -0,0 +1,42 @@ + + + + Statistics for dcav.pw + + + > + + +

Screenshot statistics for dcav.pw

+

Leaderboards

+ + + + + + + + <% count = 0 + users.sort.each do |user| + count += 1 + %> + <%= %Q{ + + + + + + } + %> + <% end %> +
NameCountSize
#{count}#{user.name}#{user.count}#{Filesize.from(user.size.to_s + "B").pretty}
+

Charts

+ /> +
+ /> +
+ /> +
+ Page generated at <%= Time.now %> + + diff --git a/gen_index.rb b/gen_index.rb new file mode 100644 index 0000000..4678a4f --- /dev/null +++ b/gen_index.rb @@ -0,0 +1,41 @@ +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