merge-requests/6/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,32 +142,26 @@ 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 eventTime= \
eventTime= \ datetime.strptime(tag['startTime'], \
datetime.strptime(tag['startTime'], \ "%Y-%m-%dT%H:%M:%S%z")
"%Y-%m-%dT%H:%M:%S%z") if int(eventTime.strftime("%Y"))==year and \
if int(eventTime.strftime("%Y"))==year and \ int(eventTime.strftime("%m"))==monthNumber and \
int(eventTime.strftime("%m"))==monthNumber and \ int(eventTime.strftime("%d"))==dayNumber:
int(eventTime.strftime("%d"))==dayNumber: eventsExist=True
eventsExist=True break
break
return eventsExist return eventsExist
@ -179,33 +188,27 @@ 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 eventTime= \
eventTime= \ datetime.strptime(tag['startTime'], \
datetime.strptime(tag['startTime'], \ "%Y-%m-%dT%H:%M:%S%z")
"%Y-%m-%dT%H:%M:%S%z") if int(eventTime.strftime("%Y"))==year and \
if int(eventTime.strftime("%Y"))==year and \ int(eventTime.strftime("%m"))==monthNumber and \
int(eventTime.strftime("%m"))==monthNumber and \ (int(eventTime.strftime("%d"))>dayNumber and \
(int(eventTime.strftime("%d"))>dayNumber and \ int(eventTime.strftime("%d"))<=dayNumber+6):
int(eventTime.strftime("%d"))<=dayNumber+6): eventsExist=True
eventsExist=True break
break
return eventsExist return eventsExist
@ -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'):
@ -328,24 +324,17 @@ def getCalendarEvents(baseDir: str,nickname: str,domain: str, \
if not postFilename: if not postFilename:
recreateEventsFile=True recreateEventsFile=True
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'):