Skip to content

Instantly share code, notes, and snippets.

@JohnWong
Last active June 6, 2022 09:27
Show Gist options
  • Save JohnWong/4d79801e55af8da1712d609ada340873 to your computer and use it in GitHub Desktop.
Save JohnWong/4d79801e55af8da1712d609ada340873 to your computer and use it in GitHub Desktop.
# sudo gem install json icalendar
require 'rubygems'
require 'open-uri'
require 'json'
require 'icalendar'
# sessions_data = JSON.parse(open("http://developer.apple.com/wwdc/data/sessions.json").read)["SessionsData"]
sessions_raw = '[{
"title": "Apple Keynote",
"description": "The Apple Worldwide Developers Conference kicks off with exciting reveals, inspiration, and new opportunities. Join the worldwide developer community for an in-depth look at the future of Apple platforms, directly from Apple Park.",
"time_start": "June 6, 10 a.m.",
"time_end": "June 6, 0 p.m."
},{
"title": "Platforms State of the Union",
"description": "The Apple Worldwide Developers Conference kicks off with exciting reveals, inspiration, and new opportunities. Join the worldwide developer community for an in-depth look at the future of Apple platforms, directly from Apple Park.",
"time_start": "June 6, 1 p.m.",
"time_end": "June 6, 3 p.m."
}]'
sessions_data = JSON.parse(sessions_raw)
calendar = Icalendar::Calendar.new
tzid = "America/Los_Angeles"
calendar.timezone do |t|
t.tzid = tzid
end
sessions_data.each do |session|
puts session[:time]
calendar.event do |e|
e.dtstart = Icalendar::Values::DateTime.new DateTime.parse(session["time_start"]), 'tzid' => tzid
e.dtend = Icalendar::Values::DateTime.new DateTime.parse(session["time_end"]), 'tzid' => tzid
e.summary = session["title"] + " [WWDC 2022]"
e.description = session["description"]
e.url = session["url"] || "https://developer.apple.com/wwdc22/"
e.alarm do |a|
a.action = "DISPLAY" # This line isn't necessary, it's the default
a.summary = "15 min before the event"
a.trigger = "-PT15M" # 15 minutes before
end
end
end
puts calendar.to_ical
File.open('WWDC.ics', 'w') { |file| file.write(calendar.to_ical) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment