Last active
July 27, 2024 23:48
-
-
Save afeld/916bbd7c26312a6e8df897a95380c2d9 to your computer and use it in GitHub Desktop.
get rehearsals from calendar - moved to https://github.com/afeld/rehearsals
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
# 1. `gem install icalendar` | |
# 2. Get the "Secret adddress in iCal format" from Google Calendar: https://support.google.com/calendar/answer/37083#link | |
# 3. Open that URL in a browser to download the .ics file | |
# 3. Modify the constants below | |
# 4. Run `ruby rehearsals.rb` | |
require "icalendar" | |
require "csv" | |
START_FROM = DateTime.new(2023, 4, 25) | |
CAL_PATH = File.expand_path("~/Downloads/basic.ics") | |
def format_time(time) | |
time.in_time_zone("America/New_York").strftime("%m/%d/%Y %H:%M:%S") | |
end | |
# # Open a file or pass a string to the parser | |
cal_file = File.open(CAL_PATH) | |
# Parser returns an array of calendars because a single file | |
# can have multiple calendars. | |
cals = Icalendar::Calendar.parse(cal_file) | |
cal = cals.first | |
CSV.open("rehearsals.csv", "w") do |csv| | |
csv << ["Name", "Location", "Start", "End"] | |
# Now you can access the cal object in just the same way I created it | |
cal.events.each do |event| | |
if event.dtstart >= START_FROM and event.summary.include? "Artichoke" | |
row = [ | |
event.summary, | |
event.location, | |
format_time(event.dtstart), | |
format_time(event.dtend) | |
] | |
puts row | |
csv << row | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment