Change name of module

main
Bob Mottram 2020-07-03 20:20:31 +01:00
parent 8019735837
commit 7d78d27e28
3 changed files with 2 additions and 91 deletions

View File

@ -1,89 +0,0 @@
__filename__ = "calendar.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import os
def receivingCalendarEvents(baseDir: str, nickname: str, domain: str,
followingNickname: str,
followingDomain: str) -> bool:
"""Returns true if receiving calendar events from the given
account from following.txt
"""
calendarFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/followingCalendar.txt'
handle = followingNickname + '@' + followingDomain
if not os.path.isfile(calendarFilename):
return False
return handle + '\n' in open(calendarFilename).read()
def receiveCalendarEvents(baseDir: str, nickname: str, domain: str,
followingNickname: str,
followingDomain: str,
add: bool) -> None:
"""Adds or removes a handle from the following.txt list into a list
indicating whether to receive calendar events from that account
"""
# check that a following file exists
followingFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/following.txt'
if not os.path.isfile(followingFilename):
return
handle = followingNickname + '@' + followingDomain
# check that you are following this handle
if handle + '\n' not in open(followingFilename).read():
return
calendarFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + '/followingCalendar.txt'
# get the contents of the calendar file, which is
# a set of handles
followingHandles = ''
if os.path.isfile(calendarFilename):
with open(calendarFilename, 'r') as calendarFile:
followingHandles = calendarFile.read()
else:
# create a new calendar file from the following file
with open(followingFilename, 'r') as followingFile:
followingHandles = followingFile.read()
with open(calendarFilename, 'w') as fp:
fp.write(followingHandles)
# already in the calendar file?
if handle + '\n' in followingHandles:
if add:
# already added
return
# remove from calendar file
followingHandles = followingHandles.replace(handle + '\n', '')
with open(calendarFilename, 'w') as fp:
fp.write(followingHandles)
else:
# not already in the calendar file
if add:
# append to the list of handles
followingHandles += handle + '\n'
with open(calendarFilename, 'w') as fp:
fp.write(followingHandles)
def addPersonToCalendar(baseDir: str, nickname: str, domain: str,
followingNickname: str,
followingDomain: str) -> None:
receiveCalendarEvents(baseDir, nickname, domain,
followingNickname, followingDomain, True)
def removePersonFromCalendar(baseDir: str, nickname: str, domain: str,
followingNickname: str,
followingDomain: str) -> None:
receiveCalendarEvents(baseDir, nickname, domain,
followingNickname, followingDomain, False)

View File

@ -62,7 +62,7 @@ from question import questionUpdateVotes
from media import replaceYouTube from media import replaceYouTube
from git import isGitPatch from git import isGitPatch
from git import receiveGitPatch from git import receiveGitPatch
from calendar import receivingCalendarEvents from followingCalendar import receivingCalendarEvents
def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None:

View File

@ -74,7 +74,7 @@ from happening import getTodaysEvents
from git import isGitPatch from git import isGitPatch
from theme import getThemesList from theme import getThemesList
from petnames import getPetName from petnames import getPetName
from calendar import receivingCalendarEvents from followingCalendar import receivingCalendarEvents
def getContentWarningButton(postID: str, translate: {}, def getContentWarningButton(postID: str, translate: {},