mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
10238f0a09
commit
64588f9d2a
|
@ -23,74 +23,74 @@ def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
|
||||||
return None
|
return None
|
||||||
if not post_json_object['object'].get('id'):
|
if not post_json_object['object'].get('id'):
|
||||||
return None
|
return None
|
||||||
conversationDir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
||||||
if not os.path.isdir(conversationDir):
|
if not os.path.isdir(conversation_dir):
|
||||||
os.mkdir(conversationDir)
|
os.mkdir(conversation_dir)
|
||||||
conversationId = post_json_object['object']['conversation']
|
conversation_id = post_json_object['object']['conversation']
|
||||||
conversationId = conversationId.replace('/', '#')
|
conversation_id = conversation_id.replace('/', '#')
|
||||||
return conversationDir + '/' + conversationId
|
return conversation_dir + '/' + conversation_id
|
||||||
|
|
||||||
|
|
||||||
def update_conversation(base_dir: str, nickname: str, domain: str,
|
def update_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
post_json_object: {}) -> bool:
|
post_json_object: {}) -> bool:
|
||||||
"""Ads a post to a conversation index in the /conversation subdirectory
|
"""Ads a post to a conversation index in the /conversation subdirectory
|
||||||
"""
|
"""
|
||||||
conversationFilename = \
|
conversation_filename = \
|
||||||
_get_conversation_filename(base_dir, nickname, domain,
|
_get_conversation_filename(base_dir, nickname, domain,
|
||||||
post_json_object)
|
post_json_object)
|
||||||
if not conversationFilename:
|
if not conversation_filename:
|
||||||
return False
|
return False
|
||||||
post_id = remove_id_ending(post_json_object['object']['id'])
|
post_id = remove_id_ending(post_json_object['object']['id'])
|
||||||
if not os.path.isfile(conversationFilename):
|
if not os.path.isfile(conversation_filename):
|
||||||
try:
|
try:
|
||||||
with open(conversationFilename, 'w+') as fp:
|
with open(conversation_filename, 'w+') as conv_file:
|
||||||
fp.write(post_id + '\n')
|
conv_file.write(post_id + '\n')
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: update_conversation ' +
|
print('EX: update_conversation ' +
|
||||||
'unable to write to ' + conversationFilename)
|
'unable to write to ' + conversation_filename)
|
||||||
elif post_id + '\n' not in open(conversationFilename).read():
|
elif post_id + '\n' not in open(conversation_filename).read():
|
||||||
try:
|
try:
|
||||||
with open(conversationFilename, 'a+') as fp:
|
with open(conversation_filename, 'a+') as conv_file:
|
||||||
fp.write(post_id + '\n')
|
conv_file.write(post_id + '\n')
|
||||||
return True
|
return True
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: update_conversation 2 ' +
|
print('EX: update_conversation 2 ' +
|
||||||
'unable to write to ' + conversationFilename)
|
'unable to write to ' + conversation_filename)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def mute_conversation(base_dir: str, nickname: str, domain: str,
|
def mute_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
conversationId: str) -> None:
|
conversation_id: str) -> None:
|
||||||
"""Mutes the given conversation
|
"""Mutes the given conversation
|
||||||
"""
|
"""
|
||||||
conversationDir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
||||||
conversationFilename = \
|
conversation_filename = \
|
||||||
conversationDir + '/' + conversationId.replace('/', '#')
|
conversation_dir + '/' + conversation_id.replace('/', '#')
|
||||||
if not os.path.isfile(conversationFilename):
|
if not os.path.isfile(conversation_filename):
|
||||||
return
|
return
|
||||||
if os.path.isfile(conversationFilename + '.muted'):
|
if os.path.isfile(conversation_filename + '.muted'):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with open(conversationFilename + '.muted', 'w+') as fp:
|
with open(conversation_filename + '.muted', 'w+') as conv_file:
|
||||||
fp.write('\n')
|
conv_file.write('\n')
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to write mute ' + conversationFilename)
|
print('EX: unable to write mute ' + conversation_filename)
|
||||||
|
|
||||||
|
|
||||||
def unmute_conversation(base_dir: str, nickname: str, domain: str,
|
def unmute_conversation(base_dir: str, nickname: str, domain: str,
|
||||||
conversationId: str) -> None:
|
conversation_id: str) -> None:
|
||||||
"""Unmutes the given conversation
|
"""Unmutes the given conversation
|
||||||
"""
|
"""
|
||||||
conversationDir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
conversation_dir = acct_dir(base_dir, nickname, domain) + '/conversation'
|
||||||
conversationFilename = \
|
conversation_filename = \
|
||||||
conversationDir + '/' + conversationId.replace('/', '#')
|
conversation_dir + '/' + conversation_id.replace('/', '#')
|
||||||
if not os.path.isfile(conversationFilename):
|
if not os.path.isfile(conversation_filename):
|
||||||
return
|
return
|
||||||
if not os.path.isfile(conversationFilename + '.muted'):
|
if not os.path.isfile(conversation_filename + '.muted'):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
os.remove(conversationFilename + '.muted')
|
os.remove(conversation_filename + '.muted')
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unmute_conversation unable to delete ' +
|
print('EX: unmute_conversation unable to delete ' +
|
||||||
conversationFilename + '.muted')
|
conversation_filename + '.muted')
|
||||||
|
|
Loading…
Reference in New Issue