commit bfe7c56bcf9ac03eca9f2b1d03373eb7acaaec3f Author: dzwdz Date: Sun Mar 28 13:35:20 2021 +0000 mirror all submissions + generate a very basic per-challenge listing diff --git a/gather.rb b/gather.rb new file mode 100755 index 0000000..5aa7bdb --- /dev/null +++ b/gather.rb @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby + +$PAGE_BASE = "http://tilde.town/~dzwdz/golf" +$LOCAL_BASE = "/home/dzwdz/public_html/golf" + +def all_files(event) + `ls -d /home/*/golf/#{event}/*` + .lines + .map(&:strip) +end + +def submissions(event) + all_files(event) + .filter {|l| not l.end_with? '.hint'} +end + +## mirrors files into public_html/golf/[event name]/mirror/ +def mirror(event) + all_files(event) + .each do |path| + split = path.split('/') + user = split[2] + name = split[5] + `mkdir -p #{$LOCAL_BASE}/#{event}/mirror/#{user}` + begin + File.symlink(path, "#{$LOCAL_BASE}/#{event}/mirror/#{user}/#{name}") + rescue Errno::EEXIST + end + end +end + + +def challenge_page(event) + # maps participants to their submissions + p_map = Hash.new [] + + submissions(event) + .each do |path| + user = path.split('/')[2] + p_map[user] += [path] + end + + file = File.new("#{$LOCAL_BASE}/#{event}/index.html", 'w') + + p_map.each do + |user, submissions| + file.print "

#{user}

\n" + end + + file.close +end + +mirror 'firstone' +challenge_page 'firstone'