Skip to content

Instantly share code, notes, and snippets.

@dmacvicar
Created July 4, 2010 14:45
Show Gist options
  • Save dmacvicar/463501 to your computer and use it in GitHub Desktop.
Save dmacvicar/463501 to your computer and use it in GitHub Desktop.
# to install the gems:
# gem install icalendar
# or
# Add devel:languages:ruby:extensions
# zypper in rubygem-icalendar
require 'rubygems'
require 'icalendar'
require 'open-uri'
require 'date'
CALENDAR_URI = "http://www.schulferien.org/iCal/Ferien/icals/Ferien_Bayern_2010.ics"
cal_file = open(CALENDAR_URI)
cals = Icalendar.parse(cal_file)
now = DateTime.now
# for every calendar in the file
cals.each do |calendar|
# and each event
calendar.events.each do |event|
# ignore past events
next if event.dtstart < now
# execute command if
puts event.summary
# (event.dtstart - now) is a rational
# measuring days
hours_to_event = ((event.dtstart - now) * 24).to_i
if hours_to_event <= 1
# execute some command
puts `ls -la`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment