birthdaze 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -0
  3. data/lib/birthdaze.rb +23 -11
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e67d3efa62158e2181f474f0c1dbf9b62769316e84ace36ac95ab5da98a9629c
4
- data.tar.gz: f529457feccd008ac0f90151ac788ee44cdd967c094fffcf198f4ab1b52fdab2
3
+ metadata.gz: 60d1e0d4cb56c5fdd6c578e7d1ef1646a1b251c64cd042e651c1552c228ef6cd
4
+ data.tar.gz: 3a4be8ee6d1387114f86cec4a4ea6e8341651809379e465ad36befa68258ff3f
5
5
  SHA512:
6
- metadata.gz: 440b163d77844aedc8107f02627206767737e476910c916a756b471a40964bb676d384133c6df5f6be64acec38e9cdf2c8860c77b698c767dc165ef84744fb57
7
- data.tar.gz: e1118b722644022c47385827f2f23f5323fee6620fb8cfd88d1afa2c0dfbbbd796709c2d2f69bf4b02a8186c36f25d0215a8fabf104e33b1be12186749025d65
6
+ metadata.gz: c8428ae748a6035cb02bab6bda57253ac86ae84d8a199b4e39aca2a6ef640733c8e31bea6e88d6081da0e7dcfa4636f5b1216e807b20fd131c5fbb3de6dcff73
7
+ data.tar.gz: d7696650ca9c4330b4f72ff0a2a3d893ad05f3d3ff61a6f83f45600ce140463ea87b471fc6b269231e2841952c5808ca7c1bfbdcb0d609cd40f8ed7174045471
data/README.md CHANGED
@@ -1,4 +1,44 @@
1
1
  # Birthdaze
2
2
 
3
+ [View on RubyGems](https://rubygems.org/gems/birthdaze)
4
+
3
5
  Birthdaze is a tool to generate a calendar of your contacts’ birthdays
4
6
  from a CardDAV server account.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ gem install ruby
12
+ ```
13
+
14
+ Note Birthdaze relies on the `curb` gem, which requires `libcurl4-openssl-dev` to be installed.
15
+
16
+ ## Setup
17
+
18
+ You’ll need a config file in the `~/.config/birthdaze.yaml` that looks like the below:
19
+
20
+ ```yaml
21
+ username: <username>
22
+ password: <password>
23
+ url: <url>
24
+ ical_output: <path to output file>
25
+ days_warning: <number of days warning>
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Print a list of all birthdays.
31
+ ```bash
32
+ birthdaze list
33
+ ```
34
+
35
+ Generate an iCalendar file of your contacts’ birthdays.
36
+ ```bash
37
+ birthdaze generate
38
+ ```
39
+
40
+ ## Notes
41
+
42
+ - If a contact has a birthdate, the birthday will be set as recurring from that year. Otherwise,
43
+ it will be set as recurring from the current year.
44
+
data/lib/birthdaze.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "carddav"
2
+ require "digest"
2
3
  require "icalendar"
3
4
  require "thor"
4
5
  require "yaml"
@@ -58,13 +59,20 @@ class Birthdaze < Thor
58
59
 
59
60
  @calendar = Icalendar::Calendar.new
60
61
  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
62
+ event = Icalendar::Event.new
63
+ event.uid = uid(birthday)
64
+ event.dtstart = Icalendar::Values::Date.new(start_date(birthday))
65
+ event.dtend = Icalendar::Values::Date.new(end_date(birthday))
66
+ event.summary = summary(birthday)
67
+ event.description = description(birthday)
68
+ event.rrule = "FREQ=YEARLY;"
69
+ event.alarm do |alarm|
70
+ alarm.action = "DISPLAY"
71
+ alarm.description = "It is #{birthday[:name]}’s birthday on #{birthday[:day]}/#{birthday[:month]}"
72
+ alarm.summary = "Birthday reminder: #{birthday[:name]}"
73
+ alarm.trigger = "-P#{config['days_warning']}D"
74
+ end if config["days_warning"]
75
+ @calendar.add_event(event)
68
76
  end
69
77
  @calendar.publish
70
78
  end
@@ -80,6 +88,13 @@ class Birthdaze < Thor
80
88
  date.strftime("%Y%m%d")
81
89
  end
82
90
 
91
+ # Format a deterministic UID for the event so it isn’t re-added every time the calendar is re-generated
92
+ def uid(birthday)
93
+ uid = Digest::SHA2.hexdigest("#{birthday[:name]}#{birthday[:day]}#{birthday[:month]}")[0..35]
94
+ uid[8] = uid[13] = uid[18] = uid[23] = '-'
95
+ uid
96
+ end
97
+
83
98
  def summary(birthday)
84
99
  "🎂 #{birthday[:name]}’s birthday"
85
100
  end
@@ -90,9 +105,6 @@ class Birthdaze < Thor
90
105
  "#{birthday[:name]} was born in #{birthday[:birth_year]}"
91
106
  end
92
107
 
93
- def set_reminders
94
- end
95
-
96
108
  def birthday_regex
97
109
  # We need the dash for dates which don’t specify a year
98
110
  /.*BDAY.*:([\d-]*).*/
@@ -114,7 +126,7 @@ class Birthdaze < Thor
114
126
  return nil if date.length < 8
115
127
 
116
128
  birth_year = date[0..3]
117
- return nil if birth_year == "1604" # This is set (for some reason) by DAVx⁵
129
+ return nil if birth_year == "1604" # This is set by some apps for birth dates without a year
118
130
  birth_year
119
131
  end
120
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birthdaze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - T S Vallender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-03 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carddav
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  requirements: []
85
- rubygems_version: 3.4.10
85
+ rubygems_version: 3.5.5
86
86
  signing_key:
87
87
  specification_version: 4
88
88
  summary: Generate a birthday calendar from CardDAV