Use deteministic UIDs

Refs #1
This commit is contained in:
Trevor Vallender 2024-03-05 11:48:13 +00:00
parent 4b108e9328
commit 0160b8abd9
1 changed files with 16 additions and 7 deletions

View File

@ -1,4 +1,5 @@
require "carddav"
require "digest"
require "icalendar"
require "thor"
require "yaml"
@ -58,13 +59,14 @@ class Birthdaze < Thor
@calendar = Icalendar::Calendar.new
birthdays.each do |birthday|
@calendar.event do |event|
event = Icalendar::Event.new
event.uid = uid(birthday)
event.dtstart = Icalendar::Values::Date.new(start_date(birthday))
event.dtend = Icalendar::Values::Date.new(end_date(birthday))
event.summary = summary(birthday)
event.description = description(birthday)
event.rrule = "FREQ=YEARLY;"
end
@calendar.add_event(event)
end
@calendar.publish
end
@ -80,6 +82,13 @@ class Birthdaze < Thor
date.strftime("%Y%m%d")
end
# Format a deterministic UID for the event so it isnt re-added every time the calendar is re-generated
def uid(birthday)
uid = Digest::SHA2.hexdigest("#{birthday[:name]}#{birthday[:day]}#{birthday[:month]}")[0..35]
uid[8] = uid[13] = uid[18] = uid[23] = '-'
uid
end
def summary(birthday)
"🎂 #{birthday[:name]}s birthday"
end