rename and update index page generator
This commit is contained in:
parent
ab9005aec4
commit
ef66639f83
42
dcav-index.erb
Normal file
42
dcav-index.erb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Statistics for dcav.pw</title>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" type="text/css" href=<%="#{RES_BASE}style.css"%>>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Screenshot statistics for dcav.pw</h1>
|
||||||
|
<h2>Leaderboards</h2>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Count</th>
|
||||||
|
<th>Size</th>
|
||||||
|
</tr>
|
||||||
|
<% count = 0
|
||||||
|
users.sort.each do |user|
|
||||||
|
count += 1
|
||||||
|
%>
|
||||||
|
<%= %Q{
|
||||||
|
<tr>
|
||||||
|
<td>#{count}</td>
|
||||||
|
<td>#{user.name}</td>
|
||||||
|
<td class=\"right-align\">#{user.count}</td>
|
||||||
|
<td class=\"right-align\">#{Filesize.from(user.size.to_s + "B").pretty}</td>
|
||||||
|
</tr>}
|
||||||
|
%>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
<h2>Charts</h2>
|
||||||
|
<img src=<%="#{RES_BASE}img/screenshot_count.svg"%> />
|
||||||
|
<br />
|
||||||
|
<img src=<%="#{RES_BASE}img/screenshot_size.svg"%> />
|
||||||
|
<br />
|
||||||
|
<img src=<%="#{RES_BASE}img/dcavpie.svg"%> />
|
||||||
|
<br />
|
||||||
|
<i>Page generated at <%= Time.now %></i>
|
||||||
|
</body>
|
||||||
|
</html>
|
41
gen_index.rb
Normal file
41
gen_index.rb
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user