Skip to content

Commit

Permalink
Merge pull request #100 from karbassi/add-profile-url. Closes #101
Browse files Browse the repository at this point in the history
Add fb profile url to ics description
  • Loading branch information
mobeigi authored May 15, 2021
2 parents 1decea1 + 04af251 commit 7a93048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fb2cal/ics_writer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import ics
from ics import Calendar, Event
from ics.grammar.parse import ContentLine
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
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 """
Expand All @@ -31,16 +31,17 @@ 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.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
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
Expand Down
6 changes: 6 additions & 0 deletions fb2cal/utils.py
Original file line number Diff line number Diff line change
@@ -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}'
8 changes: 8 additions & 0 deletions tests/test_ics_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)

0 comments on commit 7a93048

Please sign in to comment.