birthdaze 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +4 -0
- data/bin/birthdaze +5 -0
- data/lib/birthdaze.rb +120 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e67d3efa62158e2181f474f0c1dbf9b62769316e84ace36ac95ab5da98a9629c
|
4
|
+
data.tar.gz: f529457feccd008ac0f90151ac788ee44cdd967c094fffcf198f4ab1b52fdab2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 440b163d77844aedc8107f02627206767737e476910c916a756b471a40964bb676d384133c6df5f6be64acec38e9cdf2c8860c77b698c767dc165ef84744fb57
|
7
|
+
data.tar.gz: e1118b722644022c47385827f2f23f5323fee6620fb8cfd88d1afa2c0dfbbbd796709c2d2f69bf4b02a8186c36f25d0215a8fabf104e33b1be12186749025d65
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2023 David Heinemeier Hansson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/bin/birthdaze
ADDED
data/lib/birthdaze.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require "carddav"
|
2
|
+
require "icalendar"
|
3
|
+
require "thor"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
class Birthdaze < Thor
|
7
|
+
desc "generate", "Generate calendars"
|
8
|
+
def generate
|
9
|
+
puts "Writing ical file to #{config['ical_output']}"
|
10
|
+
File.open(config["ical_output"], 'w') { |file| file.write(calendar.to_ical) }
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "list", "List birthdays"
|
14
|
+
def list
|
15
|
+
bdays = birthdays.sort do |a, b|
|
16
|
+
a[:month] == b[:month] ? a[:day] <=> b[:day] : a[:month] <=> b[:month]
|
17
|
+
end
|
18
|
+
bdays.each { |d| puts "🎂 #{d[:day]}/#{d[:month]} - #{d[:name]}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def config(config_file = "#{ENV["HOME"]}/.config/birthdaze.yaml")
|
24
|
+
unless File.file?(config_file)
|
25
|
+
puts "Please add a configuration file"
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
@config ||= YAML.load_file(config_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
def client(url: config["url"], username: config["username"], password: config["password"])
|
33
|
+
@client ||= Carddav::Client.new(url, username, password)
|
34
|
+
end
|
35
|
+
|
36
|
+
def birthdays
|
37
|
+
return @birthdays if defined? @birthdays
|
38
|
+
|
39
|
+
@birthdays = []
|
40
|
+
client.cards.each do |card|
|
41
|
+
card = card.parsed.to_s
|
42
|
+
birthday = birthday_regex.match(card)[1] if birthday_regex.match?(card)
|
43
|
+
name = name_regex.match(card)[1] if name_regex.match?(card)
|
44
|
+
if name && birthday
|
45
|
+
@birthdays << {
|
46
|
+
name: name,
|
47
|
+
month: month_of(birthday),
|
48
|
+
day: day_of(birthday),
|
49
|
+
birth_year: birth_year_of(birthday)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@birthdays
|
54
|
+
end
|
55
|
+
|
56
|
+
def calendar
|
57
|
+
return @calendar if defined? @calendar
|
58
|
+
|
59
|
+
@calendar = Icalendar::Calendar.new
|
60
|
+
birthdays.each do |birthday|
|
61
|
+
@calendar.event do |event|
|
62
|
+
event.dtstart = Icalendar::Values::Date.new(start_date(birthday))
|
63
|
+
event.dtend = Icalendar::Values::Date.new(end_date(birthday))
|
64
|
+
event.summary = summary(birthday)
|
65
|
+
event.description = description(birthday)
|
66
|
+
event.rrule = "FREQ=YEARLY;"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@calendar.publish
|
70
|
+
end
|
71
|
+
|
72
|
+
# Takes a birthday string, with or without a year, and returns a start date
|
73
|
+
def start_date(birthday)
|
74
|
+
year = birthday[:birth_year] || Date.today.year
|
75
|
+
"#{year}#{birthday[:month]}#{birthday[:day]}"
|
76
|
+
end
|
77
|
+
|
78
|
+
def end_date(birthday)
|
79
|
+
date = Date.parse(start_date(birthday)).next_day
|
80
|
+
date.strftime("%Y%m%d")
|
81
|
+
end
|
82
|
+
|
83
|
+
def summary(birthday)
|
84
|
+
"🎂 #{birthday[:name]}’s birthday"
|
85
|
+
end
|
86
|
+
|
87
|
+
def description(birthday)
|
88
|
+
return "" unless birthday[:birth_year]
|
89
|
+
|
90
|
+
"#{birthday[:name]} was born in #{birthday[:birth_year]}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_reminders
|
94
|
+
end
|
95
|
+
|
96
|
+
def birthday_regex
|
97
|
+
# We need the dash for dates which don’t specify a year
|
98
|
+
/.*BDAY.*:([\d-]*).*/
|
99
|
+
end
|
100
|
+
|
101
|
+
def name_regex
|
102
|
+
/FN.*:(.*)/
|
103
|
+
end
|
104
|
+
|
105
|
+
def month_of(date)
|
106
|
+
date.tr("-", "")[-4..-3]
|
107
|
+
end
|
108
|
+
|
109
|
+
def day_of(date)
|
110
|
+
date.tr("-", "")[-2..-1]
|
111
|
+
end
|
112
|
+
|
113
|
+
def birth_year_of(date)
|
114
|
+
return nil if date.length < 8
|
115
|
+
|
116
|
+
birth_year = date[0..3]
|
117
|
+
return nil if birth_year == "1604" # This is set (for some reason) by DAVx⁵
|
118
|
+
birth_year
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: birthdaze
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- T S Vallender
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carddav
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: icalendar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email: t@tsvallender.co.uk
|
57
|
+
executables:
|
58
|
+
- birthdaze
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- bin/birthdaze
|
65
|
+
- lib/birthdaze.rb
|
66
|
+
homepage: https://git.tsvallender.co.uk/tsv/birthdaze
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.4.10
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Generate a birthday calendar from CardDAV
|
89
|
+
test_files: []
|