#!/usr/bin/env ruby # # Copyright(C) Simon Howard # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # Prints plain-text versions of latest commits from # CIA (http://cia.navi.cx/). Useful for piping into # your screensaver. # require 'net/http' h = Net::HTTP.new('cia.navi.cx', 80) resp, data = h.get('/stats/total/commits/.xml', nil) input = '' data.each_line do |s| s.chomp! input += s+"NEWLINE" end def expand_text(s) s = s.gsub(/\/, "\n") s = s.gsub(/\<.*?\>/, '') s = s.gsub(/\<\;/, "<") s = s.gsub(/\>\;/, ">") s = s.gsub(/\&\;/, "&") s = s.gsub(/NEWLINE/, "\n") s end def project(data) data =~ /\(.*)\<\/project\>/ project_name = $1 if data =~ /\(.*)\<\/module\>/ project_name += "::#{$1}" end puts '-' * 30 puts project_name puts message = '' if data =~ /\(.*)\<\/colorText\>/ message = expand_text($1) end if data =~ /\(.*)\<\/log\>/ message = expand_text($1) end while message[-1] == "\n"[0] message.chop! end puts message puts end puts ' ___ ___ _ ' puts ' / __|_ _| /_\ ' puts '| (__ | | / _ \ ' puts ' \___|___/_/ \_\\' puts input.gsub(/\(.*?)\<\/message\>/) do project($1) end