#!/usr/bin/env ruby require 'date' activities = {} activity = /[\s]+([^\s].+)[\W]{1,}#(.+)/ next_activities = [] start_entry = /(\d{2}\:\d{2})\-(\d{2}\:\d{2})/ time_worked = 0 file_to_parse = ARGV[0] File.open(file_to_parse).each do |line| # parse out time spent, ignoring any lines starting with "-Lunch" or "-Break" match = start_entry.match(line) if match and !(line =~ /\-Break/) and !(line =~ /\-Lunch/) event_end = DateTime.parse(match[2]) event_start = DateTime.parse(match[1]) time_spent_mins = (event_end.hour * 60 + event_end.min) - (event_start.hour * 60 + event_start.min) time_worked += time_spent_mins end # parse out any activities (marked by a "#" tag at the end of the line) match = activity.match(line) if match thing_done = match[1].strip tag = match[2].strip activities[tag] = [] unless activities.has_key?(tag) activities[tag] << thing_done end # parse out any +NEXT lines (should be on their own line and not mixed with # tags) match = /\+NEXT\s+(.+)/.match(line) if match next_activities << match[1] end end activities = activities.sort hours = time_worked / 60 hour_fraction = (time_worked % 60) / 60.0 warn "*************************************\n" warn "Worked #{hours + hour_fraction} hours\n" puts "*************************************\n" puts "This week:\n\n" activities.each do |tag, things_done| puts tag + ":\n\n" things_done.each {|thing| puts " * #{thing}"} puts "\n" end puts "*************************************\n" puts "Next:\n\n" if next_activities.empty? puts "Nothing planned yet" else next_activities.each {|n| puts " * " + n} end puts "\n"