Print a forecast of upcoming events from iCal files
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix today/tomorrow, parse files as binary

+5 -5
+5 -5
ical_forecast.rb
··· 49 49 end 50 50 51 51 ARGV.each do |file| 52 - RiCal.parse(File.open(file)).first.events.each do |ev| 52 + RiCal.parse(File.open(file, "rb")).first.events.each do |ev| 53 53 ev.occurrences(:count => 10).each do |oc| 54 54 begin 55 55 start = oc.dtstart.to_time.getlocal ··· 72 72 finish = ev.dtend.to_time.getlocal 73 73 74 74 weeks = 0 75 - days = ((start - Time.now) / (60 * 60 * 24)).ceil 76 - if days > 7 75 + days = (start.to_date - Date.today).to_i 76 + if days >= 7 77 77 weeks = (days.to_f / 7.0).floor 78 78 days = days - (weeks * 7) 79 79 end ··· 81 81 out = "" 82 82 if weeks == 0 && days == 0 83 83 out << BOLD 84 - elsif weeks == 1 84 + elsif weeks <= 1 85 85 out << GRAY 86 86 elsif weeks > 1 87 87 out << LIGHTGRAY ··· 116 116 out << " at #{start.strftime("%H:%M")}" 117 117 118 118 if start.to_date == Time.now.to_date 119 - mins = ((Time.now - start) / 60).floor 119 + mins = ((start - Time.now) / 60).floor 120 120 if start < Time.now 121 121 out << " (#{mins} minute#{mins == 1 ? "" : "s"} ago)" 122 122 else