main
Bob Mottram 2020-02-23 09:42:09 +00:00
parent 09e9ff5616
commit f0f818197e
1 changed files with 42 additions and 33 deletions

View File

@ -192,6 +192,7 @@ def thisWeeksEventsCheck(baseDir: str,nickname: str,domain: str) -> bool:
def getThisWeeksEvents(baseDir: str,nickname: str,domain: str) -> {}: def getThisWeeksEvents(baseDir: str,nickname: str,domain: str) -> {}:
"""Retrieves calendar events for this week """Retrieves calendar events for this week
Returns a dictionary indexed by day number of lists containing Event and Place activities Returns a dictionary indexed by day number of lists containing Event and Place activities
Note: currently not used but could be with a weekly calendar screen
""" """
now=datetime.now() now=datetime.now()
year=now.year year=now.year
@ -275,7 +276,8 @@ def getThisWeeksEvents(baseDir: str,nickname: str,domain: str) -> {}:
return events return events
def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumber: int) -> {}: def getCalendarEvents(baseDir: str,nickname: str,domain: str, \
year: int,monthNumber: int) -> {}:
"""Retrieves calendar events """Retrieves calendar events
Returns a dictionary indexed by day number of lists containing Event and Place activities Returns a dictionary indexed by day number of lists containing Event and Place activities
""" """
@ -291,38 +293,45 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str,year: int,monthNumb
postFilename=locatePost(baseDir,nickname,domain,postId) postFilename=locatePost(baseDir,nickname,domain,postId)
if not postFilename: if not postFilename:
recreateEventsFile=True recreateEventsFile=True
else: continue
postJsonObject=loadJson(postFilename)
if postJsonObject: postJsonObject=loadJson(postFilename)
if postJsonObject.get('object'): if not postJsonObject:
if isinstance(postJsonObject['object'], dict): continue
if postJsonObject['object'].get('tag'): if not postJsonObject.get('object'):
postEvent=[] continue
dayOfMonth=None if not isinstance(postJsonObject['object'], dict):
for tag in postJsonObject['object']['tag']: continue
if not tag.get('type'): if not postJsonObject['object'].get('tag'):
continue continue
if tag['type']!='Event' and tag['type']!='Place':
continue postEvent=[]
if tag['type']=='Event': dayOfMonth=None
# tag is an event for tag in postJsonObject['object']['tag']:
if not tag.get('startTime'): if not tag.get('type'):
continue continue
eventTime= \ if tag['type']!='Event' and tag['type']!='Place':
datetime.strptime(tag['startTime'], \ continue
"%Y-%m-%dT%H:%M:%S%z") if tag['type']=='Event':
if int(eventTime.strftime("%Y"))==year and \ # tag is an event
int(eventTime.strftime("%m"))==monthNumber: if not tag.get('startTime'):
dayOfMonth=str(int(eventTime.strftime("%d"))) continue
postEvent.append(tag) eventTime= \
else: datetime.strptime(tag['startTime'], \
# tag is a place "%Y-%m-%dT%H:%M:%S%z")
postEvent.append(tag) if int(eventTime.strftime("%Y"))==year and \
if postEvent and dayOfMonth: int(eventTime.strftime("%m"))==monthNumber:
calendarPostIds.append(postId) dayOfMonth=str(int(eventTime.strftime("%d")))
if not events.get(dayOfMonth): postEvent.append(tag)
events[dayOfMonth]=[] else:
events[dayOfMonth].append(postEvent) # tag is a place
postEvent.append(tag)
if postEvent and dayOfMonth:
calendarPostIds.append(postId)
if not events.get(dayOfMonth):
events[dayOfMonth]=[]
events[dayOfMonth].append(postEvent)
# if some posts have been deleted then regenerate the calendar file # if some posts have been deleted then regenerate the calendar file
if recreateEventsFile: if recreateEventsFile: