Save calendar events to file

main2
Bob Mottram 2019-10-11 13:31:06 +01:00
parent 002c400e40
commit 7ab0901721
1 changed files with 40 additions and 0 deletions

View File

@ -1354,6 +1354,44 @@ def sendToGroupMembers(session,baseDir: str,handle: str,port: int,postJsonObject
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug,projectVersion) personCache,debug,projectVersion)
def inboxUpdateCalendar(baseDir: str,handle: str,postJsonObject: {}) -> None:
"""Detects whether the tag list on a post contains calendar events
and if so saves the post id to a file in the calendar directory
for the account
"""
if not postJsonObject.get('object'):
return
if not isinstance(postJsonObject['object'], dict):
return
if not postJsonObject['object'].get('tag'):
return
if not isinstance(postJsonObject['object']['tag'], list):
return
calendarPath=os.path.isdir(baseDir+'/accounts/'+handle+'/calendar'
if not os.path.isdir(calendarPath):
os.mkdir(calendarPath)
for tagDict in postJsonObject['object']['tag']:
if tagDict['type']!='Event':
continue
if not tagDict['type'].get('startTime'):
continue
# get the year and month from the event
eventTime= \
datetime.datetime.strptime(tag['startTime'], \
"%Y-%m-%dT%H:%M:%SZ")
eventYear=int(eventTime.strftime("%Y"))
eventMonthNumber=int(eventTime.strftime("%m"))
if not os.path.isdir(calendarPath+'/'+str(eventYear)):
os.mkdir(calendarPath+'/'+str(eventYear))
calendarFilename=calendarPath+'/'+str(eventYear)+'/'+str(eventMonthNumber)+'.txt'
calendarFile=open(calendarFilename,'a+')
if calendarFile:
calendarFile.write(postJsonObject['id'].replace('/','#')+'\n')
calendarFile.close()
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
baseDir: str,httpPrefix: str,sendThreads: [], \ baseDir: str,httpPrefix: str,sendThreads: [], \
postLog: [],cachedWebfingers: {},personCache: {}, \ postLog: [],cachedWebfingers: {},personCache: {}, \
@ -1480,6 +1518,8 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
except Exception as e: except Exception as e:
print(e) print(e)
inboxUpdateCalendar(baseDir,handle,postJsonObject)
# send the post out to group members # send the post out to group members
if isGroup: if isGroup:
sendToGroupMembers(session,baseDir,handle,port,postJsonObject, \ sendToGroupMembers(session,baseDir,handle,port,postJsonObject, \