Parse dates from CardDAV
We’re now correctly building an array of names and birthdates from CardDAV data
This commit is contained in:
parent
a73e0e7a0b
commit
d4508ca8be
|
@ -6,22 +6,42 @@ class Birthdaze < Thor
|
|||
desc "generate", "Generate calendars"
|
||||
def generate
|
||||
puts "Generate calendars"
|
||||
auth(config["url"], config["username"], config["password"])
|
||||
birthdays
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def config
|
||||
config_file = "#{ENV["HOME"]}/.config/birthdaze.yaml"
|
||||
def config(config_file = "#{ENV["HOME"]}/.config/birthdaze.yaml")
|
||||
unless File.file?(config_file)
|
||||
puts "Please add a configuration file"
|
||||
return
|
||||
end
|
||||
|
||||
@config ||= YAML.load_file(config_file)
|
||||
end
|
||||
|
||||
def auth(url, username, password)
|
||||
config
|
||||
client = Carddav::Client.new(url, username, password)
|
||||
def client(url: config["url"], username: config["username"], password: config["password"])
|
||||
@client ||= Carddav::Client.new(url, username, password)
|
||||
end
|
||||
|
||||
def birthdays
|
||||
birthdays = []
|
||||
client.cards.each do |card|
|
||||
card = card.parsed.to_s
|
||||
birthday = birthday_regex.match(card)[1] if birthday_regex.match?(card)
|
||||
name = name_regex.match(card)[1] if name_regex.match?(card)
|
||||
birthdays << [ name, birthday ] if name && birthday
|
||||
end
|
||||
puts birthdays
|
||||
birthdays
|
||||
end
|
||||
|
||||
def birthday_regex
|
||||
# We need the dash for dates which don’t specify a year
|
||||
/.*BDAY.*:([\d-]*).*/
|
||||
end
|
||||
|
||||
def name_regex
|
||||
/FN.*:(.*)/
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue