From 873556775183bde049c4ed55f219cfbc3c2761c5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 13 Aug 2020 09:37:11 +0000 Subject: [PATCH] Comments --- inbox.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/inbox.py b/inbox.py index 15bf74a2..3015f54c 100644 --- a/inbox.py +++ b/inbox.py @@ -1970,6 +1970,8 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None: handleNickname, handleDomain, actorNickname, actorDomain): return + + # look for events within the tags list for tagDict in postJsonObject['object']['tag']: if not tagDict.get('type'): continue @@ -1977,26 +1979,38 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None: continue if not tagDict.get('startTime'): continue - # get the year and month from the event + + # get the year, month and day from the event eventTime = datetime.datetime.strptime(tagDict['startTime'], "%Y-%m-%dT%H:%M:%S%z") eventYear = int(eventTime.strftime("%Y")) eventMonthNumber = int(eventTime.strftime("%m")) eventDayOfMonth = int(eventTime.strftime("%d")) + # create a directory for the calendar year if not os.path.isdir(calendarPath + '/' + str(eventYear)): os.mkdir(calendarPath + '/' + str(eventYear)) + + # calendar month file containing event post Ids calendarFilename = calendarPath + '/' + str(eventYear) + \ '/' + str(eventMonthNumber) + '.txt' postId = \ postJsonObject['id'].replace('/activity', '').replace('/', '#') + + # Does this event post already exist within the calendar month? if os.path.isfile(calendarFilename): if postId in open(calendarFilename).read(): + # Event post already exists return + + # append the post Id to the file for the calendar month calendarFile = open(calendarFilename, 'a+') if calendarFile: calendarFile.write(postId + '\n') calendarFile.close() + + # create a file which will trigger a notification that + # a new event has been added calendarNotificationFilename = \ baseDir + '/accounts/' + handle + '/.newCalendar' calendarNotificationFile = \