Snake case

merge-requests/30/head
Bob Mottram 2022-01-03 12:41:06 +00:00
parent 7f563e3653
commit c20a208d61
1 changed files with 45 additions and 40 deletions

View File

@ -13,92 +13,97 @@ from utils import acct_dir
def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str, def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
followingNickname: str, following_nickname: str,
followingDomain: str, following_domain: str,
add: bool) -> None: add: bool) -> None:
"""Adds or removes a handle from the following.txt list into a list """Adds or removes a handle from the following.txt list into a list
indicating whether to notify when a new post arrives from that account indicating whether to notify when a new post arrives from that account
""" """
# check that a following file exists # check that a following file exists
domain = remove_domain_port(domain) domain = remove_domain_port(domain)
followingFilename = acct_dir(base_dir, nickname, domain) + '/following.txt' following_filename = \
if not os.path.isfile(followingFilename): acct_dir(base_dir, nickname, domain) + '/following.txt'
if not os.path.isfile(following_filename):
print("WARN: following.txt doesn't exist for " + print("WARN: following.txt doesn't exist for " +
nickname + '@' + domain) nickname + '@' + domain)
return return
handle = followingNickname + '@' + followingDomain handle = following_nickname + '@' + following_domain
# check that you are following this handle # check that you are following this handle
if handle + '\n' not in open(followingFilename).read(): if handle + '\n' not in open(following_filename).read():
print('WARN: ' + handle + ' is not in ' + followingFilename) print('WARN: ' + handle + ' is not in ' + following_filename)
return return
notifyOnPostFilename = \ notify_on_post_filename = \
acct_dir(base_dir, nickname, domain) + '/notifyOnPost.txt' acct_dir(base_dir, nickname, domain) + '/notifyOnPost.txt'
# get the contents of the notifyOnPost file, which is # get the contents of the notifyOnPost file, which is
# a set of handles # a set of handles
followingHandles = '' following_handles = ''
if os.path.isfile(notifyOnPostFilename): if os.path.isfile(notify_on_post_filename):
print('notify file exists') print('notify file exists')
with open(notifyOnPostFilename, 'r') as calendarFile: with open(notify_on_post_filename, 'r') as calendar_file:
followingHandles = calendarFile.read() following_handles = calendar_file.read()
else: else:
# create a new notifyOnPost file from the following file # create a new notifyOnPost file from the following file
print('Creating notifyOnPost file ' + notifyOnPostFilename) print('Creating notifyOnPost file ' + notify_on_post_filename)
followingHandles = '' following_handles = ''
with open(followingFilename, 'r') as followingFile: with open(following_filename, 'r') as following_file:
followingHandles = followingFile.read() following_handles = following_file.read()
if add: if add:
with open(notifyOnPostFilename, 'w+') as fp: with open(notify_on_post_filename, 'w+') as fp_notify:
fp.write(followingHandles + handle + '\n') fp_notify.write(following_handles + handle + '\n')
# already in the notifyOnPost file? # already in the notifyOnPost file?
if handle + '\n' in followingHandles: if handle + '\n' in following_handles:
print(handle + ' exists in notifyOnPost.txt') print(handle + ' exists in notifyOnPost.txt')
if add: if add:
# already added # already added
return return
# remove from calendar file # remove from calendar file
followingHandles = followingHandles.replace(handle + '\n', '') following_handles = following_handles.replace(handle + '\n', '')
with open(notifyOnPostFilename, 'w+') as fp: with open(notify_on_post_filename, 'w+') as fp_notify:
fp.write(followingHandles) fp_notify.write(following_handles)
else: else:
print(handle + ' not in notifyOnPost.txt') print(handle + ' not in notifyOnPost.txt')
# not already in the notifyOnPost file # not already in the notifyOnPost file
if add: if add:
# append to the list of handles # append to the list of handles
followingHandles += handle + '\n' following_handles += handle + '\n'
with open(notifyOnPostFilename, 'w+') as fp: with open(notify_on_post_filename, 'w+') as fp_notify:
fp.write(followingHandles) fp_notify.write(following_handles)
def add_notify_on_post(base_dir: str, nickname: str, domain: str, def add_notify_on_post(base_dir: str, nickname: str, domain: str,
followingNickname: str, following_nickname: str,
followingDomain: str) -> None: following_domain: str) -> None:
"""Add a notification
"""
_notify_on_post_arrival(base_dir, nickname, domain, _notify_on_post_arrival(base_dir, nickname, domain,
followingNickname, followingDomain, True) following_nickname, following_domain, True)
def remove_notify_on_post(base_dir: str, nickname: str, domain: str, def remove_notify_on_post(base_dir: str, nickname: str, domain: str,
followingNickname: str, following_nickname: str,
followingDomain: str) -> None: following_domain: str) -> None:
"""Remove a notification
"""
_notify_on_post_arrival(base_dir, nickname, domain, _notify_on_post_arrival(base_dir, nickname, domain,
followingNickname, followingDomain, False) following_nickname, following_domain, False)
def notify_when_person_posts(base_dir: str, nickname: str, domain: str, def notify_when_person_posts(base_dir: str, nickname: str, domain: str,
followingNickname: str, following_nickname: str,
followingDomain: str) -> bool: following_domain: str) -> bool:
"""Returns true if receiving notifications when the given publishes a post """Returns true if receiving notifications when the given publishes a post
""" """
if followingNickname == nickname and followingDomain == domain: if following_nickname == nickname and following_domain == domain:
return False return False
notifyOnPostFilename = \ notify_on_post_filename = \
acct_dir(base_dir, nickname, domain) + '/notifyOnPost.txt' acct_dir(base_dir, nickname, domain) + '/notifyOnPost.txt'
handle = followingNickname + '@' + followingDomain handle = following_nickname + '@' + following_domain
if not os.path.isfile(notifyOnPostFilename): if not os.path.isfile(notify_on_post_filename):
# create a new notifyOnPost file # create a new notifyOnPost file
with open(notifyOnPostFilename, 'w+') as fp: with open(notify_on_post_filename, 'w+') as fp_notify:
fp.write('') fp_notify.write('')
return handle + '\n' in open(notifyOnPostFilename).read() return handle + '\n' in open(notify_on_post_filename).read()