mirror of https://gitlab.com/bashrc2/epicyon
Separate event creation function
parent
8735567751
commit
37b86507c5
54
happening.py
54
happening.py
|
@ -15,6 +15,60 @@ from utils import daysInMonth
|
||||||
from utils import mergeDicts
|
from utils import mergeDicts
|
||||||
|
|
||||||
|
|
||||||
|
def saveEvent(baseDir: str, handle: str, postId: str,
|
||||||
|
eventJson: {}) -> bool:
|
||||||
|
"""Saves an event to the calendar
|
||||||
|
"""
|
||||||
|
calendarPath = baseDir + '/accounts/' + handle + '/calendar'
|
||||||
|
if not os.path.isdir(calendarPath):
|
||||||
|
os.mkdir(calendarPath)
|
||||||
|
|
||||||
|
# get the year, month and day from the event
|
||||||
|
eventTime = datetime.strptime(eventJson['startTime'],
|
||||||
|
"%Y-%m-%dT%H:%M:%S%z")
|
||||||
|
eventYear = int(eventTime.strftime("%Y"))
|
||||||
|
eventMonthNumber = int(eventTime.strftime("%m"))
|
||||||
|
eventDayOfMonth = int(eventTime.strftime("%d"))
|
||||||
|
|
||||||
|
# create a directory for the calendar year
|
||||||
|
if not os.path.isdir(calendarPath + '/' + str(eventYear)):
|
||||||
|
os.mkdir(calendarPath + '/' + str(eventYear))
|
||||||
|
|
||||||
|
# calendar month file containing event post Ids
|
||||||
|
calendarFilename = calendarPath + '/' + str(eventYear) + \
|
||||||
|
'/' + str(eventMonthNumber) + '.txt'
|
||||||
|
|
||||||
|
# Does this event post already exist within the calendar month?
|
||||||
|
if os.path.isfile(calendarFilename):
|
||||||
|
if postId in open(calendarFilename).read():
|
||||||
|
# Event post already exists
|
||||||
|
return False
|
||||||
|
|
||||||
|
# append the post Id to the file for the calendar month
|
||||||
|
calendarFile = open(calendarFilename, 'a+')
|
||||||
|
if not calendarFile:
|
||||||
|
return False
|
||||||
|
calendarFile.write(postId + '\n')
|
||||||
|
calendarFile.close()
|
||||||
|
|
||||||
|
# create a file which will trigger a notification that
|
||||||
|
# a new event has been added
|
||||||
|
calendarNotificationFilename = \
|
||||||
|
baseDir + '/accounts/' + handle + '/.newCalendar'
|
||||||
|
calendarNotificationFile = \
|
||||||
|
open(calendarNotificationFilename, 'w+')
|
||||||
|
if not calendarNotificationFile:
|
||||||
|
return False
|
||||||
|
calendarNotificationFile.write('/calendar?year=' +
|
||||||
|
str(eventYear) +
|
||||||
|
'?month=' +
|
||||||
|
str(eventMonthNumber) +
|
||||||
|
'?day=' +
|
||||||
|
str(eventDayOfMonth))
|
||||||
|
calendarNotificationFile.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def isHappeningEvent(tag: {}) -> bool:
|
def isHappeningEvent(tag: {}) -> bool:
|
||||||
"""Is this tag an Event or Place ActivityStreams type?
|
"""Is this tag an Event or Place ActivityStreams type?
|
||||||
"""
|
"""
|
||||||
|
|
53
inbox.py
53
inbox.py
|
@ -64,6 +64,7 @@ from git import isGitPatch
|
||||||
from git import receiveGitPatch
|
from git import receiveGitPatch
|
||||||
from followingCalendar import receivingCalendarEvents
|
from followingCalendar import receivingCalendarEvents
|
||||||
from content import dangerousMarkup
|
from content import dangerousMarkup
|
||||||
|
from happening import saveEvent
|
||||||
|
|
||||||
|
|
||||||
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:
|
||||||
|
@ -1957,10 +1958,6 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
|
||||||
if not isinstance(postJsonObject['object']['tag'], list):
|
if not isinstance(postJsonObject['object']['tag'], list):
|
||||||
return
|
return
|
||||||
|
|
||||||
calendarPath = baseDir + '/accounts/' + handle + '/calendar'
|
|
||||||
if not os.path.isdir(calendarPath):
|
|
||||||
os.mkdir(calendarPath)
|
|
||||||
|
|
||||||
actor = postJsonObject['actor']
|
actor = postJsonObject['actor']
|
||||||
actorNickname = getNicknameFromActor(actor)
|
actorNickname = getNicknameFromActor(actor)
|
||||||
actorDomain, actorPort = getDomainFromActor(actor)
|
actorDomain, actorPort = getDomainFromActor(actor)
|
||||||
|
@ -1971,6 +1968,9 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
|
||||||
actorNickname, actorDomain):
|
actorNickname, actorDomain):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
postId = \
|
||||||
|
postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
||||||
|
|
||||||
# look for events within the tags list
|
# 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'):
|
||||||
|
@ -1979,50 +1979,7 @@ def inboxUpdateCalendar(baseDir: str, handle: str, postJsonObject: {}) -> None:
|
||||||
continue
|
continue
|
||||||
if not tagDict.get('startTime'):
|
if not tagDict.get('startTime'):
|
||||||
continue
|
continue
|
||||||
|
saveEvent(baseDir, handle, postId, tagDict)
|
||||||
# get the year, month and day from the event
|
|
||||||
eventTime = datetime.datetime.strptime(tagDict['startTime'],
|
|
||||||
"%Y-%m-%dT%H:%M:%S%z")
|
|
||||||
eventYear = int(eventTime.strftime("%Y"))
|
|
||||||
eventMonthNumber = int(eventTime.strftime("%m"))
|
|
||||||
eventDayOfMonth = int(eventTime.strftime("%d"))
|
|
||||||
|
|
||||||
# create a directory for the calendar year
|
|
||||||
if not os.path.isdir(calendarPath + '/' + str(eventYear)):
|
|
||||||
os.mkdir(calendarPath + '/' + str(eventYear))
|
|
||||||
|
|
||||||
# calendar month file containing event post Ids
|
|
||||||
calendarFilename = calendarPath + '/' + str(eventYear) + \
|
|
||||||
'/' + str(eventMonthNumber) + '.txt'
|
|
||||||
postId = \
|
|
||||||
postJsonObject['id'].replace('/activity', '').replace('/', '#')
|
|
||||||
|
|
||||||
# Does this event post already exist within the calendar month?
|
|
||||||
if os.path.isfile(calendarFilename):
|
|
||||||
if postId in open(calendarFilename).read():
|
|
||||||
# Event post already exists
|
|
||||||
return
|
|
||||||
|
|
||||||
# append the post Id to the file for the calendar month
|
|
||||||
calendarFile = open(calendarFilename, 'a+')
|
|
||||||
if calendarFile:
|
|
||||||
calendarFile.write(postId + '\n')
|
|
||||||
calendarFile.close()
|
|
||||||
|
|
||||||
# create a file which will trigger a notification that
|
|
||||||
# a new event has been added
|
|
||||||
calendarNotificationFilename = \
|
|
||||||
baseDir + '/accounts/' + handle + '/.newCalendar'
|
|
||||||
calendarNotificationFile = \
|
|
||||||
open(calendarNotificationFilename, 'w+')
|
|
||||||
if calendarNotificationFile:
|
|
||||||
calendarNotificationFile.write('/calendar?year=' +
|
|
||||||
str(eventYear) +
|
|
||||||
'?month=' +
|
|
||||||
str(eventMonthNumber) +
|
|
||||||
'?day=' +
|
|
||||||
str(eventDayOfMonth))
|
|
||||||
calendarNotificationFile.close()
|
|
||||||
|
|
||||||
|
|
||||||
def inboxUpdateIndex(boxname: str, baseDir: str, handle: str,
|
def inboxUpdateIndex(boxname: str, baseDir: str, handle: str,
|
||||||
|
|
Loading…
Reference in New Issue