diff --git a/config.rb b/config.rb new file mode 100644 index 0000000..3a7cd1c --- /dev/null +++ b/config.rb @@ -0,0 +1,6 @@ +RES_BASE = "https://strawberry.thedevcave.net/~christoffermadsen/" +USERNAMES = ["christoffermadsen","jmaa","jacob","alexander"] +SHOT_DIR = "/var/shots/" +ERB_FILE = "dcav-index.erb" +HTML_FILE = "/var/shots/html/index.html" +LOG_DIR = "./log/" diff --git a/gen_index.rb b/gen_index.rb index 557052c..9d806a1 100644 --- a/gen_index.rb +++ b/gen_index.rb @@ -1,11 +1,12 @@ require 'erb' require 'filesize' -RES_BASE = "https://strawberry.thedevcave.net/~christoffermadsen/" -usernames = ["christoffermadsen","jmaa","jacob","alexander"] -shot_dir = "/var/shots/" -erb_file = "dcav-index.erb" -html_file = "/var/shots/html/index.html" +load 'config.rb' + +usernames = USERNAMES +shot_dir = SHOT_DIR +erb_file = ERB_FILE +html_file = HTML_FILE class User attr_accessor :name, :count, :size, :avgsize diff --git a/plot.rb b/plot.rb index 7b81635..33221ea 100644 --- a/plot.rb +++ b/plot.rb @@ -1,11 +1,15 @@ # coding: utf-8 -users = ["christoffermadsen","jmaa","jacob","alexander"] -colors = {} +load 'config.rb' + +users = USERNAMES +log_dir = LOG_DIR + +colors = {} users.each do |user| colors[user] = "%06x" % (rand * 0xffffff) end -log_dir = "./log/" + plotstring = %Q[set terminal 'svg' size 800,400 fname 'Verdana, Helvetica, Arial, sans-serif' \ fsize '14' rounded dashed set key bottom center outside horizontal diff --git a/update.rb b/update.rb index 532470b..3e047df 100644 --- a/update.rb +++ b/update.rb @@ -1,15 +1,18 @@ -users = ["christoffermadsen","jmaa","alexander","jacob"] -shot_dir = "/var/shots/" -log_dir = "./log/" +load 'config.rb' + +users = USERNAMES +shot_dir = SHOT_DIR +log_dir = LOG_DIR + users.each do |user| - size = `du -B1 #{shot_dir}#{user}/ | awk {'print $1'} | head -n 1` + size = `du -B1 #{shot_dir}#{user}/ | awk {'print $1'} | head -n 1` count = `ls -1 #{shot_dir}#{user}/ | wc -l | head -n 1` [size,count].each do |x| x.delete! "\n" end - output = File.open("#{log_dir}/#{user}.log","a") - output << "#{Time.now.to_i} #{count} #{size}\n" - output.close + File.open("#{log_dir}/#{user}.log","a") do |f| + f << "#{Time.now.to_i} #{count} #{size}\n" + end end