Last active
December 20, 2017 08:32
-
-
Save mktakuya/075c7fe0e4b151dadfd58c01faa87026 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
# https://github.com/mktakuya/sinatra-icalendar-sample | |
require 'json' | |
require 'sinatra' | |
require 'icalendar' | |
get '/tnct-adv' do | |
calendar = Icalendar::Calendar.new | |
calendar.append_custom_property("X-WR-CALNAME;VALUE=TEXT", "苫小牧高専アドベントカレンダー2017カレンダー") | |
calendar.timezone do |t| | |
t.tzid = 'Asia/Tokyo' | |
t.standard do |s| | |
s.tzoffsetfrom = '+0900' | |
s.tzoffsetto = '+0900' | |
s.tzname = 'JST' | |
s.dtstart = '19700101T000000' | |
end | |
end | |
json = JSON.parse(File.read('./tomakomai-kosen-adv-2017.json')) | |
json['entries'].each do |entry| | |
calendar.event do |e| | |
e.dtstart = Icalendar::Values::Date.new(Date.parse(entry['date'])) | |
e.summary = entry['title'] | |
e.description = "#{entry['title']}\n#{entry['url']}" | |
end | |
end | |
calendar.publish | |
content_type 'text/calendar' | |
calendar.to_ical | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment