Compare commits
No commits in common. "b7ae662fc9934ea2575720f7423f5250d7c0b218" and "b4cc830bf8c78546ceff5f3fdc98dba05f31d0e9" have entirely different histories.
b7ae662fc9
...
b4cc830bf8
|
@ -3,7 +3,6 @@ PATH
|
||||||
specs:
|
specs:
|
||||||
birthdaze (0.0.1)
|
birthdaze (0.0.1)
|
||||||
carddav
|
carddav
|
||||||
icalendar
|
|
||||||
thor
|
thor
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
|
@ -14,9 +13,6 @@ GEM
|
||||||
nokogiri
|
nokogiri
|
||||||
vcardigan
|
vcardigan
|
||||||
curb (1.0.5)
|
curb (1.0.5)
|
||||||
icalendar (2.10.1)
|
|
||||||
ice_cube (~> 0.16)
|
|
||||||
ice_cube (0.16.4)
|
|
||||||
nokogiri (1.16.2-x86_64-linux)
|
nokogiri (1.16.2-x86_64-linux)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
racc (1.7.3)
|
racc (1.7.3)
|
||||||
|
|
Binary file not shown.
|
@ -5,12 +5,10 @@ Gem::Specification.new do |s|
|
||||||
s.authors = ["T S Vallender"]
|
s.authors = ["T S Vallender"]
|
||||||
s.email = "t@tsvallender.co.uk"
|
s.email = "t@tsvallender.co.uk"
|
||||||
s.homepage = "https://git.tsvallender.co.uk/tsv/birthdaze"
|
s.homepage = "https://git.tsvallender.co.uk/tsv/birthdaze"
|
||||||
s.files = Dir["bin/*", "lib/**/*", "MIT-LICENSE", "README.md"]
|
s.files = Dir["lib/**/*", "MIT-LICENSE", "README.md"]
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.bindir = "bin"
|
|
||||||
s.executables << "birthdaze"
|
s.executables << "birthdaze"
|
||||||
s.add_dependency "carddav"
|
|
||||||
s.add_dependency "icalendar"
|
|
||||||
s.add_dependency "thor"
|
s.add_dependency "thor"
|
||||||
|
s.add_dependency "carddav"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
require "carddav"
|
require "carddav"
|
||||||
require "icalendar"
|
|
||||||
require "thor"
|
require "thor"
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
class Birthdaze < Thor
|
class Birthdaze < Thor
|
||||||
desc "generate", "Generate calendars"
|
desc "generate", "Generate calendars"
|
||||||
def generate
|
def generate
|
||||||
puts "Writing ical file to #{config['ical_output']}"
|
puts "Generate calendars"
|
||||||
File.open(config["ical_output"], 'w') { |file| file.write(calendar.to_ical) }
|
birthdays
|
||||||
end
|
|
||||||
|
|
||||||
desc "list", "List birthdays"
|
|
||||||
def list
|
|
||||||
bdays = birthdays.sort do |a, b|
|
|
||||||
a[:month] == b[:month] ? a[:day] <=> b[:day] : a[:month] <=> b[:month]
|
|
||||||
end
|
|
||||||
bdays.each { |d| puts "🎂 #{d[:day]}/#{d[:month]} - #{d[:name]}" }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -34,63 +25,14 @@ class Birthdaze < Thor
|
||||||
end
|
end
|
||||||
|
|
||||||
def birthdays
|
def birthdays
|
||||||
return @birthdays if defined? @birthdays
|
birthdays = []
|
||||||
|
|
||||||
@birthdays = []
|
|
||||||
client.cards.each do |card|
|
client.cards.each do |card|
|
||||||
card = card.parsed.to_s
|
card = card.parsed.to_s
|
||||||
birthday = birthday_regex.match(card)[1] if birthday_regex.match?(card)
|
birthday = birthday_regex.match(card)[1] if birthday_regex.match?(card)
|
||||||
name = name_regex.match(card)[1] if name_regex.match?(card)
|
name = name_regex.match(card)[1] if name_regex.match?(card)
|
||||||
if name && birthday
|
birthdays << [ name, birthday ] if name && birthday
|
||||||
@birthdays << {
|
|
||||||
name: name,
|
|
||||||
month: month_of(birthday),
|
|
||||||
day: day_of(birthday),
|
|
||||||
birth_year: birth_year_of(birthday)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@birthdays
|
birthdays
|
||||||
end
|
|
||||||
|
|
||||||
def calendar
|
|
||||||
return @calendar if defined? @calendar
|
|
||||||
|
|
||||||
@calendar = Icalendar::Calendar.new
|
|
||||||
birthdays.each do |birthday|
|
|
||||||
@calendar.event do |event|
|
|
||||||
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
|
|
||||||
end
|
|
||||||
@calendar.publish
|
|
||||||
end
|
|
||||||
|
|
||||||
# Takes a birthday string, with or without a year, and returns a start date
|
|
||||||
def start_date(birthday)
|
|
||||||
year = birthday[:birth_year] || Date.today.year
|
|
||||||
"#{year}#{birthday[:month]}#{birthday[:day]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def end_date(birthday)
|
|
||||||
date = Date.parse(start_date(birthday)).next_day
|
|
||||||
date.strftime("%Y%m%d")
|
|
||||||
end
|
|
||||||
|
|
||||||
def summary(birthday)
|
|
||||||
"🎂 #{birthday[:name]}’s birthday"
|
|
||||||
end
|
|
||||||
|
|
||||||
def description(birthday)
|
|
||||||
return "" unless birthday[:birth_year]
|
|
||||||
|
|
||||||
"#{birthday[:name]} was born in #{birthday[:birth_year]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_reminders
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def birthday_regex
|
def birthday_regex
|
||||||
|
@ -101,20 +43,4 @@ class Birthdaze < Thor
|
||||||
def name_regex
|
def name_regex
|
||||||
/FN.*:(.*)/
|
/FN.*:(.*)/
|
||||||
end
|
end
|
||||||
|
|
||||||
def month_of(date)
|
|
||||||
date.tr("-", "")[-4..-3]
|
|
||||||
end
|
|
||||||
|
|
||||||
def day_of(date)
|
|
||||||
date.tr("-", "")[-2..-1]
|
|
||||||
end
|
|
||||||
|
|
||||||
def birth_year_of(date)
|
|
||||||
return nil if date.length < 8
|
|
||||||
|
|
||||||
birth_year = date[0..3]
|
|
||||||
return nil if birth_year == "1604" # This is set (for some reason) by DAVx⁵
|
|
||||||
birth_year
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue