mirror of https://gitlab.com/bashrc2/epicyon
Replace file operations with functions
parent
4a1ee28e8d
commit
c5b9626bd8
93
follow.py
93
follow.py
|
|
@ -46,6 +46,7 @@ from session import get_json_valid
|
||||||
from session import post_json
|
from session import post_json
|
||||||
from followerSync import remove_followers_sync
|
from followerSync import remove_followers_sync
|
||||||
from data import load_string
|
from data import load_string
|
||||||
|
from data import append_string
|
||||||
from data import load_list
|
from data import load_list
|
||||||
from data import save_string
|
from data import save_string
|
||||||
|
|
||||||
|
|
@ -347,21 +348,13 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
|
||||||
if os.path.isfile(unfollowed_filename):
|
if os.path.isfile(unfollowed_filename):
|
||||||
if not text_in_file(handle_to_unfollow_lower,
|
if not text_in_file(handle_to_unfollow_lower,
|
||||||
unfollowed_filename, False):
|
unfollowed_filename, False):
|
||||||
try:
|
append_string(handle_to_unfollow + '\n', unfollowed_filename,
|
||||||
with open(unfollowed_filename, 'a+',
|
'EX: unfollow_account unable to append ' +
|
||||||
encoding='utf-8') as fp_unfoll:
|
unfollowed_filename)
|
||||||
fp_unfoll.write(handle_to_unfollow + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: unfollow_account unable to append ' +
|
|
||||||
unfollowed_filename)
|
|
||||||
else:
|
else:
|
||||||
try:
|
save_string(handle_to_unfollow + '\n', unfollowed_filename,
|
||||||
with open(unfollowed_filename, 'w+',
|
'EX: unfollow_account unable to write ' +
|
||||||
encoding='utf-8') as fp_unfoll:
|
unfollowed_filename)
|
||||||
fp_unfoll.write(handle_to_unfollow + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: unfollow_account unable to write ' +
|
|
||||||
unfollowed_filename)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -656,13 +649,11 @@ def store_follow_request(base_dir: str,
|
||||||
if os.path.isfile(followers_filename):
|
if os.path.isfile(followers_filename):
|
||||||
already_following = False
|
already_following = False
|
||||||
|
|
||||||
followers_str = ''
|
followers_str = \
|
||||||
try:
|
load_string(followers_filename,
|
||||||
with open(followers_filename, 'r',
|
'EX: store_follow_request ' + followers_filename)
|
||||||
encoding='utf-8') as fp_foll:
|
if followers_str is None:
|
||||||
followers_str = fp_foll.read()
|
followers_str = ''
|
||||||
except OSError:
|
|
||||||
print('EX: store_follow_request ' + followers_filename)
|
|
||||||
|
|
||||||
if approve_handle in followers_str:
|
if approve_handle in followers_str:
|
||||||
already_following = True
|
already_following = True
|
||||||
|
|
@ -708,23 +699,18 @@ def store_follow_request(base_dir: str,
|
||||||
|
|
||||||
if os.path.isfile(approve_follows_filename):
|
if os.path.isfile(approve_follows_filename):
|
||||||
if not text_in_file(approve_handle, approve_follows_filename):
|
if not text_in_file(approve_handle, approve_follows_filename):
|
||||||
try:
|
append_string(approve_handle_stored + '\n',
|
||||||
with open(approve_follows_filename, 'a+',
|
approve_follows_filename,
|
||||||
encoding='utf-8') as fp_approve:
|
'EX: store_follow_request 2 ' +
|
||||||
fp_approve.write(approve_handle_stored + '\n')
|
approve_follows_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: store_follow_request 2 ' + approve_follows_filename)
|
|
||||||
else:
|
else:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: ' + approve_handle_stored +
|
print('DEBUG: ' + approve_handle_stored +
|
||||||
' is already awaiting approval')
|
' is already awaiting approval')
|
||||||
else:
|
else:
|
||||||
try:
|
save_string(approve_handle_stored + '\n',
|
||||||
with open(approve_follows_filename, 'w+',
|
approve_follows_filename,
|
||||||
encoding='utf-8') as fp_approve:
|
'EX: store_follow_request 3 ' + approve_follows_filename)
|
||||||
fp_approve.write(approve_handle_stored + '\n')
|
|
||||||
except OSError:
|
|
||||||
print('EX: store_follow_request 3 ' + approve_follows_filename)
|
|
||||||
|
|
||||||
# store the follow request in its own directory
|
# store the follow request in its own directory
|
||||||
# We don't rely upon the inbox because items in there could expire
|
# We don't rely upon the inbox because items in there could expire
|
||||||
|
|
@ -957,23 +943,15 @@ def send_follow_request(session, base_dir: str,
|
||||||
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
|
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
|
||||||
if os.path.isfile(unfollowed_filename):
|
if os.path.isfile(unfollowed_filename):
|
||||||
if text_in_file(follow_handle, unfollowed_filename):
|
if text_in_file(follow_handle, unfollowed_filename):
|
||||||
unfollowed_file = None
|
unfollowed_file = \
|
||||||
try:
|
load_string(unfollowed_filename,
|
||||||
with open(unfollowed_filename, 'r',
|
'EX: send_follow_request ' + unfollowed_filename)
|
||||||
encoding='utf-8') as fp_unfoll:
|
|
||||||
unfollowed_file = fp_unfoll.read()
|
|
||||||
except OSError:
|
|
||||||
print('EX: send_follow_request ' + unfollowed_filename)
|
|
||||||
if unfollowed_file:
|
if unfollowed_file:
|
||||||
unfollowed_file = \
|
unfollowed_file = \
|
||||||
unfollowed_file.replace(follow_handle + '\n', '')
|
unfollowed_file.replace(follow_handle + '\n', '')
|
||||||
try:
|
save_string(unfollowed_file, unfollowed_filename,
|
||||||
with open(unfollowed_filename, 'w+',
|
'EX: send_follow_request unable to write ' +
|
||||||
encoding='utf-8') as fp_unfoll:
|
unfollowed_filename)
|
||||||
fp_unfoll.write(unfollowed_file)
|
|
||||||
except OSError:
|
|
||||||
print('EX: send_follow_request unable to write ' +
|
|
||||||
unfollowed_filename)
|
|
||||||
|
|
||||||
new_follow_json = {
|
new_follow_json = {
|
||||||
"@context": [
|
"@context": [
|
||||||
|
|
@ -1554,13 +1532,11 @@ def remove_follower(base_dir: str,
|
||||||
acct_dir(base_dir, nickname, domain) + '/followers.txt'
|
acct_dir(base_dir, nickname, domain) + '/followers.txt'
|
||||||
if not os.path.isfile(followers_filename):
|
if not os.path.isfile(followers_filename):
|
||||||
return False
|
return False
|
||||||
followers_str = ''
|
followers_str = \
|
||||||
try:
|
load_string(followers_filename,
|
||||||
with open(followers_filename, 'r', encoding='utf-8') as fp_foll:
|
'EX: remove_follower unable to read followers ' +
|
||||||
followers_str = fp_foll.read()
|
followers_filename)
|
||||||
except OSError:
|
if followers_str is None:
|
||||||
print('EX: remove_follower unable to read followers ' +
|
|
||||||
followers_filename)
|
|
||||||
return False
|
return False
|
||||||
followers_list = followers_str.split('\n')
|
followers_list = followers_str.split('\n')
|
||||||
|
|
||||||
|
|
@ -1577,12 +1553,9 @@ def remove_follower(base_dir: str,
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
return False
|
return False
|
||||||
try:
|
save_string(new_followers_str, followers_filename,
|
||||||
with open(followers_filename, 'w+', encoding='utf-8') as fp_foll:
|
'EX: remove_follower unable to write followers ' +
|
||||||
fp_foll.write(new_followers_str)
|
followers_filename)
|
||||||
except OSError:
|
|
||||||
print('EX: remove_follower unable to write followers ' +
|
|
||||||
followers_filename)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue