lib/waddup/sources/apple_calendar.rb in waddup-0.0.2 vs lib/waddup/sources/apple_calendar.rb in waddup-0.1.0
- old
+ new
@@ -1,50 +1,33 @@
module Waddup
class Source::AppleCalendar < Waddup::Source
include Waddup::Extension::AppleScript
extend Waddup::Extension::AppleScript
+ extend Waddup::Extension::FileSystem
ALIAS = 'ical'
ICON = "\xF0\x9F\x93\x85 "
- EVENT_SCRIPT = %Q{
- on run argv
- set window_from to date (item 1 of argv)
- set window_to to date (item 2 of argv)
+ EVENT_SCRIPT = folder_of(__FILE__) + 'apple_calender/events.applescript'
- tell application "Calendar"
- set results to {}
-
- set cdars to (events whose start date <= window_to and end date > window_from) in every calendar
- repeat with cdar in cdars
- repeat with evt in cdar
- set end of results to {summary:summary of evt, start_date:start date of evt as string, end_date:end date of evt as string}
- end repeat
- end repeat
-
- results
- end tell
- end run
- }
-
# Aggregates calendar events
#
# Arguments:
#
# :from (datetime)
# :to (datetime)
#
def events(from, to)
results = applescript EVENT_SCRIPT,
- :as_ruby => true,
- :args => [from.strftime('%d/%m/%Y %H:%M'), to.strftime('%d/%m/%Y %H:%M')]
+ as_ruby: true,
+ args: [from.strftime('%d/%m/%Y %H:%M'), to.strftime('%d/%m/%Y %H:%M')]
results.map do |result|
Waddup::Event.new do |e|
e.label = result[:summary]
- e.at = DateTime.parse(result[:start_date])
- e.until = DateTime.parse(result[:end_date])
+ e.at = Time.parse(result[:start_date])
+ e.until = Time.parse(result[:end_date])
e.source = self
end
end
end