From 7e0d6f28ca82b2f69f6baec8d61a551d423cb900 Mon Sep 17 00:00:00 2001 From: Ali Karbassi Date: Fri, 14 May 2021 10:24:15 -0500 Subject: [PATCH 1/2] Add fb profile url to ics description --- fb2cal/ics_writer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fb2cal/ics_writer.py b/fb2cal/ics_writer.py index 19980f1..0b1ce0c 100644 --- a/fb2cal/ics_writer.py +++ b/fb2cal/ics_writer.py @@ -35,12 +35,13 @@ def generate(self): # Don't add extra 's' if name already ends with 's' formatted_username = f"{facebook_user.name}'s" if facebook_user.name[-1] != 's' else f"{facebook_user.name}'" e.name = f"{formatted_username} Birthday" + e.description = facebook_user.profile_url # Calculate the year as this year or next year based on if its past current month or not # Also pad day, month with leading zeros to 2dp year = cur_date.year if facebook_user.birthday_month >= cur_date.month else (cur_date + relativedelta(years=1)).year - - # Feb 29 special case: + + # Feb 29 special case: # If event year is not a leap year, use Feb 28 as birthday date instead if facebook_user.birthday_month == 2 and facebook_user.birthday_day == 29 and not calendar.isleap(year): facebook_user.birthday_day = 28 From 04af25166c7fabd4e30f92db5c2ed40a70c900a3 Mon Sep 17 00:00:00 2001 From: Mo Beigi Date: Sat, 15 May 2021 17:01:47 +1000 Subject: [PATCH 2/2] Add permalink url to description of events and update tests --- fb2cal/ics_writer.py | 6 +++--- fb2cal/utils.py | 6 ++++++ tests/test_ics_writer.py | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 fb2cal/utils.py diff --git a/fb2cal/ics_writer.py b/fb2cal/ics_writer.py index 0b1ce0c..c0f66e7 100644 --- a/fb2cal/ics_writer.py +++ b/fb2cal/ics_writer.py @@ -1,5 +1,4 @@ import os -import ics from ics import Calendar, Event from ics.grammar.parse import ContentLine from datetime import datetime, timedelta @@ -7,6 +6,7 @@ import calendar from .logger import Logger +from .utils import generate_facebook_profile_url_permalink from .__init__ import __version__, __status__, __website__ """ Write Birthdays to an ICS file """ @@ -31,11 +31,11 @@ def generate(self): e = Event() e.uid = facebook_user.id e.created = cur_date + e.description = f'{facebook_user.name}\n{generate_facebook_profile_url_permalink(facebook_user)}' # Don't add extra 's' if name already ends with 's' formatted_username = f"{facebook_user.name}'s" if facebook_user.name[-1] != 's' else f"{facebook_user.name}'" - e.name = f"{formatted_username} Birthday" - e.description = facebook_user.profile_url + e.name = f'{formatted_username} Birthday' # Calculate the year as this year or next year based on if its past current month or not # Also pad day, month with leading zeros to 2dp diff --git a/fb2cal/utils.py b/fb2cal/utils.py new file mode 100644 index 0000000..2207d65 --- /dev/null +++ b/fb2cal/utils.py @@ -0,0 +1,6 @@ +from .facebook_user import FacebookUser + +# Generates permalink to Facebook profile url +# This is needed in many cases as the vanity url may change over time +def generate_facebook_profile_url_permalink(facebook_user: FacebookUser): + return f'https://www.facebook.com/{facebook_user.id}' diff --git a/tests/test_ics_writer.py b/tests/test_ics_writer.py index dd347d4..3c405ef 100644 --- a/tests/test_ics_writer.py +++ b/tests/test_ics_writer.py @@ -80,6 +80,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20210120 DTSTAMP:20201113T071402Z +DESCRIPTION:John Smith\\nhttps://www.facebook.com/100000000 DURATION:P1D SUMMARY:John Smith's Birthday UID:100000000 @@ -88,6 +89,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20210312 DTSTAMP:20201113T071402Z +DESCRIPTION:Laura Daisy\\nhttps://www.facebook.com/100000001 DURATION:P1D SUMMARY:Laura Daisy's Birthday UID:100000001 @@ -96,6 +98,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20210606 DTSTAMP:20201113T071402Z +DESCRIPTION:韩忠清\\nhttps://www.facebook.com/100000002 DURATION:P1D SUMMARY:韩忠清's Birthday UID:100000002 @@ -104,6 +107,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20211026 DTSTAMP:20201113T071402Z +DESCRIPTION:حكيم هديّة\\nhttps://www.facebook.com/100000003 DURATION:P1D SUMMARY:حكيم هديّة's Birthday UID:100000003 @@ -112,6 +116,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20210228 DTSTAMP:20201113T071402Z +DESCRIPTION:Leap Year\\nhttps://www.facebook.com/100000004 DURATION:P1D SUMMARY:Leap Year's Birthday UID:100000004 @@ -120,6 +125,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20201231 DTSTAMP:20201113T071402Z +DESCRIPTION:Mónica Bellucci\\nhttps://www.facebook.com/100000005 DURATION:P1D SUMMARY:Mónica Bellucci's Birthday UID:100000005 @@ -128,6 +134,7 @@ def test_ics_writer_equivalence(self): RRULE:FREQ=YEARLY DTSTART;VALUE=DATE:20210524 DTSTAMP:20201113T071402Z +DESCRIPTION:Bob Jones\\nhttps://www.facebook.com/100000006 DURATION:P1D SUMMARY:Bob Jones' Birthday UID:100000006 @@ -145,3 +152,4 @@ def test_ics_writer_equivalence(self): self.assertEqual(actual.name, expected.name) self.assertEqual(actual.begin, expected.begin) self.assertEqual(actual.duration, expected.duration) + self.assertEqual(actual.description, expected.description)