epicyon/relationships.py

54 lines
1.6 KiB
Python
Raw Normal View History

2022-11-27 20:35:12 +00:00
__filename__ = "relationships.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.3.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Core"
import os
from utils import acct_dir
def get_moved_accounts(base_dir: str, nickname: str, domain: str,
filename: str = 'following.txt') -> {}:
"""returns a dict of moved accounts
"""
refollow_filename = base_dir + '/accounts/actors_moved.txt'
if not os.path.isfile(refollow_filename):
return {}
refollow_str = ''
try:
with open(refollow_filename, 'r',
encoding='utf-8') as fp_refollow:
refollow_str = fp_refollow.read()
except OSError:
print('EX: get_moved_accounts unable to read ' +
refollow_filename)
refollow_list = refollow_str.split('\n')
2022-11-27 20:44:47 +00:00
refollow_dict = {}
for line in refollow_list:
prev_handle = line.split(' ')[0]
new_handle = line.split(' ')[1]
refollow_dict[prev_handle] = new_handle
2022-11-27 20:35:12 +00:00
follow_filename = \
acct_dir(base_dir, nickname, domain) + '/' + filename
follow_str = ''
try:
with open(follow_filename, 'r',
encoding='utf-8') as fp_follow:
follow_str = fp_follow.read()
except OSError:
print('EX: get_moved_accounts unable to read ' +
follow_filename)
follow_list = follow_str.split('\n')
result = {}
for handle in follow_list:
2022-11-27 20:44:47 +00:00
if refollow_dict.get(handle):
2022-11-27 20:45:23 +00:00
result[handle] = refollow_dict[handle]
2022-11-27 20:35:12 +00:00
return result