merge-requests/30/head
Bob Mottram 2020-02-24 11:10:48 +00:00
parent 56d42a2e86
commit 9ddb607cd1
1 changed files with 63 additions and 74 deletions

View File

@ -16,6 +16,28 @@ from utils import locatePost
from utils import daysInMonth from utils import daysInMonth
from utils import mergeDicts from utils import mergeDicts
def isHappeningEvent(tag: {}) -> bool:
"""Is this tag an Event or Place ActivityStreams type?
"""
if not tag.get('type'):
return False
if tag['type']!='Event' and tag['type']!='Place':
return False
return True
def isHappeningPost(postJsonObject: {}) -> bool:
"""Is this a post with tags?
"""
if not postJsonObject:
return False
if not postJsonObject.get('object'):
return False
if not isinstance(postJsonObject['object'], dict):
return False
if not postJsonObject['object'].get('tag'):
return False
return True
def getTodaysEvents(baseDir: str,nickname: str,domain: str, \ def getTodaysEvents(baseDir: str,nickname: str,domain: str, \
currYear=None,currMonthNumber=None, \ currYear=None,currMonthNumber=None, \
currDayOfMonth=None) -> {}: currDayOfMonth=None) -> {}:
@ -54,22 +76,15 @@ def getTodaysEvents(baseDir: str,nickname: str,domain: str, \
continue continue
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if not postJsonObject: if not isHappeningPost(postJsonObject):
continue
if not postJsonObject.get('object'):
continue
if not isinstance(postJsonObject['object'], dict):
continue
if not postJsonObject['object'].get('tag'):
continue continue
postEvent=[] postEvent=[]
dayOfMonth=None dayOfMonth=None
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not tag.get('type'): if not isHappeningEvent(tag):
continue
if tag['type']!='Event' and tag['type']!='Place':
continue continue
# this tag is an event or a place
if tag['type']=='Event': if tag['type']=='Event':
# tag is an event # tag is an event
if not tag.get('startTime'): if not tag.get('startTime'):
@ -127,21 +142,15 @@ def todaysEventsCheck(baseDir: str,nickname: str,domain: str) -> bool:
continue continue
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if not postJsonObject: if not isHappeningPost(postJsonObject):
continue
if not postJsonObject.get('object'):
continue
if not isinstance(postJsonObject['object'], dict):
continue
if not postJsonObject['object'].get('tag'):
continue continue
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not tag.get('type'): if not isHappeningEvent(tag):
continue continue
if tag['type']!='Event' and tag['type']!='Place': # this tag is an event or a place
if tag['type']!='Event':
continue continue
if tag['type']=='Event':
# tag is an event # tag is an event
if not tag.get('startTime'): if not tag.get('startTime'):
continue continue
@ -179,21 +188,15 @@ def thisWeeksEventsCheck(baseDir: str,nickname: str,domain: str) -> bool:
continue continue
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if not postJsonObject: if not isHappeningPost(postJsonObject):
continue
if not postJsonObject.get('object'):
continue
if not isinstance(postJsonObject['object'], dict):
continue
if not postJsonObject['object'].get('tag'):
continue continue
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not tag.get('type'): if not isHappeningEvent(tag):
continue continue
if tag['type']!='Event' and tag['type']!='Place': # this tag is an event or a place
if tag['type']!='Event':
continue continue
if tag['type']=='Event':
# tag is an event # tag is an event
if not tag.get('startTime'): if not tag.get('startTime'):
continue continue
@ -239,23 +242,16 @@ def getThisWeeksEvents(baseDir: str,nickname: str,domain: str) -> {}:
continue continue
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if not postJsonObject: if not isHappeningPost(postJsonObject):
continue
if not postJsonObject.get('object'):
continue
if not isinstance(postJsonObject['object'], dict):
continue
if not postJsonObject['object'].get('tag'):
continue continue
postEvent=[] postEvent=[]
dayOfMonth=None dayOfMonth=None
weekDayIndex=None weekDayIndex=None
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not tag.get('type'): if not isHappeningEvent(tag):
continue
if tag['type']!='Event' and tag['type']!='Place':
continue continue
# this tag is an event or a place
if tag['type']=='Event': if tag['type']=='Event':
# tag is an event # tag is an event
if not tag.get('startTime'): if not tag.get('startTime'):
@ -330,22 +326,15 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str, \
continue continue
postJsonObject=loadJson(postFilename) postJsonObject=loadJson(postFilename)
if not postJsonObject: if not isHappeningPost(postJsonObject):
continue
if not postJsonObject.get('object'):
continue
if not isinstance(postJsonObject['object'], dict):
continue
if not postJsonObject['object'].get('tag'):
continue continue
postEvent=[] postEvent=[]
dayOfMonth=None dayOfMonth=None
for tag in postJsonObject['object']['tag']: for tag in postJsonObject['object']['tag']:
if not tag.get('type'): if not isHappeningEvent(tag):
continue
if tag['type']!='Event' and tag['type']!='Place':
continue continue
# this tag is an event or a place
if tag['type']=='Event': if tag['type']=='Event':
# tag is an event # tag is an event
if not tag.get('startTime'): if not tag.get('startTime'):