-
-
Save dsisnero/3ff351dd1abe345b22a9f00c1a6ecf14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'win32ole' | |
olFolderCalendar = 9 | |
WIN32OLE.codepage = WIN32OLE::CP_UTF8 | |
ol = | |
begin | |
WIN32OLE.connect("Outlook.Application") | |
rescue | |
WIN32OLE.new("Outlook.Application") | |
end | |
items = ol.Session.GetDefaultFolder(olFolderCalendar).Items | |
items.Sort "[Start]" | |
items.IncludeRecurrences = true | |
now = Time.now | |
today = Time.new(now.year, now.month, now.day) | |
seven = Time.at(today + 8 * 24 * 60 * 60) | |
body = <<'EOT' | |
BEGIN:VCALENDAR | |
BEGIN:VTIMEZONE | |
TZID:Asia/Tokyo | |
BEGIN:STANDARD | |
TZOFFSETFROM:+0900 | |
TZOFFSETTO:+0900 | |
TZNAME:JST | |
DTSTART:19700101T000000 | |
END:STANDARD | |
END:VTIMEZONE | |
EOT | |
count = 0 | |
STATUS_VALUES = ["CANCELLED", "TENTATIVE", "CONFIRMED"] | |
filter = | |
"[Start] >= '#{today.strftime("%Y/%m/%d %H:%M")}'" + | |
" AND [End] <= '#{seven.strftime("%Y/%m/%d")}'" + | |
" AND [BusyStatus] > 0" | |
e = items.Find(filter) | |
while e | |
valarm = 1 < e.BusyStatus && today < e.Start ? <<'EOT' : "" | |
BEGIN:VALARM | |
ACTION:DISPLAY | |
TRIGGER;VALUE=DURATION:-PT5M | |
END:VALARM | |
EOT | |
body << <<"EOT" | |
BEGIN:VEVENT | |
UID:#{count+=1} | |
SUMMARY:#{e.Subject} [#{STATUS_VALUES[e.BusyStatus][0,2]}] | |
DTSTART;TZID=Asia/Tokyo:#{e.Start.strftime("%Y%m%dT%H%M%S")} | |
DTEND;TZID=Asia/Tokyo:#{e.End.strftime("%Y%m%dT%H%M%S")} | |
LOCATION:#{e.Location} | |
STATUS:#{STATUS_VALUES[e.BusyStatus]} | |
ATTENDEE;ROLE=REQ-PARTICIPANT:#{e.RequiredAttendees} | |
DESCRIPTION:#{e.Body.gsub(/\r?\n/, '\n')} | |
#{valarm}END:VEVENT | |
EOT | |
e = items.FindNext | |
end | |
body << "END:VCALENDAR\n" | |
ARGV[0] ? IO.write(ARGV[0], body) : puts(body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment