main
Bob Mottram 2020-08-13 09:37:11 +00:00
parent bbad9879c1
commit 8735567751
1 changed files with 15 additions and 1 deletions

View File

@ -1970,6 +1970,8 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
handleNickname, handleDomain, handleNickname, handleDomain,
actorNickname, actorDomain): actorNickname, actorDomain):
return return
# look for events within the tags list
for tagDict in postJsonObject['object']['tag']: for tagDict in postJsonObject['object']['tag']:
if not tagDict.get('type'): if not tagDict.get('type'):
continue continue
@ -1977,26 +1979,38 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
continue continue
if not tagDict.get('startTime'): if not tagDict.get('startTime'):
continue continue
# get the year and month from the event
# get the year, month and day from the event
eventTime = datetime.datetime.strptime(tagDict['startTime'], eventTime = datetime.datetime.strptime(tagDict['startTime'],
"%Y-%m-%dT%H:%M:%S%z") "%Y-%m-%dT%H:%M:%S%z")
eventYear = int(eventTime.strftime("%Y")) eventYear = int(eventTime.strftime("%Y"))
eventMonthNumber = int(eventTime.strftime("%m")) eventMonthNumber = int(eventTime.strftime("%m"))
eventDayOfMonth = int(eventTime.strftime("%d")) eventDayOfMonth = int(eventTime.strftime("%d"))
# create a directory for the calendar year
if not os.path.isdir(calendarPath + '/' + str(eventYear)): if not os.path.isdir(calendarPath + '/' + str(eventYear)):
os.mkdir(calendarPath + '/' + str(eventYear)) os.mkdir(calendarPath + '/' + str(eventYear))
# calendar month file containing event post Ids
calendarFilename = calendarPath + '/' + str(eventYear) + \ calendarFilename = calendarPath + '/' + str(eventYear) + \
'/' + str(eventMonthNumber) + '.txt' '/' + str(eventMonthNumber) + '.txt'
postId = \ postId = \
postJsonObject['id'].replace('/activity', '').replace('/', '#') postJsonObject['id'].replace('/activity', '').replace('/', '#')
# Does this event post already exist within the calendar month?
if os.path.isfile(calendarFilename): if os.path.isfile(calendarFilename):
if postId in open(calendarFilename).read(): if postId in open(calendarFilename).read():
# Event post already exists
return return
# append the post Id to the file for the calendar month
calendarFile = open(calendarFilename, 'a+') calendarFile = open(calendarFilename, 'a+')
if calendarFile: if calendarFile:
calendarFile.write(postId + '\n') calendarFile.write(postId + '\n')
calendarFile.close() calendarFile.close()
# create a file which will trigger a notification that
# a new event has been added
calendarNotificationFilename = \ calendarNotificationFilename = \
baseDir + '/accounts/' + handle + '/.newCalendar' baseDir + '/accounts/' + handle + '/.newCalendar'
calendarNotificationFile = \ calendarNotificationFile = \