# # Copyright 2008 Ryan E. Pfister # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Agenda script - Fetches your tasks from Remember The Milk task list and your events from your Google Calendar. Speaks them or prints them out depending on arguments supplied # Customize CALENDAR_URL and RTM_URL to your private feeds. Note that you'll need to enable private feeds in RTM. Also, fill in PRINTER_ADDRESS # USAGE: ruby agenda.rb speak/print [speak/print] # For example, you could supply the arguments: speak print # This would speak and print the agenda. # If no arguments are supplied, it will just print the agenda. require 'win32/sapi5' include Win32 require 'rexml/document' require "open-uri" require 'rubygems' require 'icalendar' require 'date' include Icalendar include REXML CALENDAR_URL = "" #FILL IN WITH YOUR URL RTM_URL ="" #FILL IN WITH YOUR URL PRINTER_ADDRESS = "" #Put the UNC path to your printer here. You will need to share your printer for this to work. def create_voice v = SpVoice.new voices = v.GetVoices v.Voice = voices.Item(1) v end def get_tasks task_names = [] file = open(RTM_URL) doc = Document.new(file) entries = doc.root.get_elements("entry") entries.each do |entry| begin date = DateTime.parse(entry.get_elements("content/div/div/span")[1].text) if(date.strftime("%m-%d") == Date.today.next.strftime("%m-%d")) break #quit when hits tomorrow's tasks end task_names << entry.get_elements("title")[0].text rescue end end task_names end class SimpleEvent attr :summary attr :dtstart attr :allday include Comparable def initialize(summary,dtstart,allday=false) @summary = summary @dtstart = dtstart @allday = allday end def <=>(anOther) dtstart <=> anOther.dtstart end end def get_events events = [] cals = Icalendar.parse(open(CALENDAR_URL)) cal = cals.first cal.events.each do |event| if event.dtstart.hour != 0 event_date = event.dtstart.new_offset('-04:00') #dates are four hours off -- you may need to adjust this value based on your PC's settings if event_date === Date.today events << SimpleEvent.new(event.summary,event_date) end else #if hour is zero, it's an "all day event" so don't adjust for time zone if event.dtstart === Date.today events << SimpleEvent.new(event.summary,event.dtstart,true) end end end events.sort! return create_event_strings(events) end def create_event_strings(events) event_strings = [] events.each do |event| if event.allday event_strings << event.summary else event_strings << event.summary + " at " + event.dtstart.strftime("%I:%M%p") end end event_strings end def print_agenda file = File.new("agenda.txt","w+") tasks = get_tasks events = get_events file.puts("AGENDA FOR " + Date.today.strftime("%m-%d-%y")) file.puts("-------------------------------------------") file.puts("TASKS:") tasks.each do |task_name| file.puts(task_name) end file.puts("\n-------------------------------------------\n") file.puts("EVENTS:") events.each do |event_string| file.puts(event_string) end file.puts("-------------------------------------------") file.close `NET USE LPT1: #{PRINTER_ADDRESS} /PERSISTENT:NO` `print agenda.txt` `NET USE /delete LPT1` end def speak_agenda v = create_voice tasks = get_tasks events = get_events v.Speak("Good morning Ryan. You have the following tasks due today.") tasks.each do |task_name| v.Speak(task_name) end v.Speak("You also have the following events today.") events.each do |event_string| v.Speak event_string end v.Speak("Have a good day!") end def main if ARGV.length > 0 ARGV.each do |arg| if arg == "speak" speak_agenda elsif arg == "print" print_agenda end end else print_agenda end end main