Function to get moved accounts

main
Bob Mottram 2022-11-27 20:35:12 +00:00
parent cf461cba20
commit fdbe400def
3 changed files with 103 additions and 1 deletions

View File

@ -111,6 +111,7 @@ from desktop_client import run_desktop_client
from happening import dav_month_via_server
from happening import dav_day_via_server
from content import import_emoji
from relationships import get_moved_accounts
def str2bool(value_str) -> bool:
@ -343,6 +344,9 @@ def _command_options() -> None:
parser.add_argument('--posts', dest='posts', type=str,
default=None,
help='Show posts for the given handle')
parser.add_argument('--moved', dest='moved', type=str,
default=None,
help='Show moved accounts for the given handle')
parser.add_argument('--postDomains', dest='postDomains', type=str,
default=None,
help='Show domains referenced in public '
@ -860,6 +864,45 @@ def _command_options() -> None:
signing_priv_key_pem, origin_domain)
sys.exit()
if argb.moved:
if not argb.domain:
origin_domain = get_config_param(base_dir, 'domain')
else:
origin_domain = argb.domain
if debug:
print('origin_domain: ' + str(origin_domain))
if '@' not in argb.moved:
if '/users/' in argb.moved:
moved_nickname = get_nickname_from_actor(argb.moved)
moved_domain, moved_port = get_domain_from_actor(argb.moved)
argb.moved = \
get_full_domain(moved_nickname + '@' + moved_domain,
moved_port)
else:
print('Syntax: --moved nickname@domain')
sys.exit()
if not argb.http:
argb.port = 443
nickname = argb.moved.split('@')[0]
domain = argb.moved.split('@')[1]
proxy_type = None
if argb.tor or domain.endswith('.onion'):
proxy_type = 'tor'
if domain.endswith('.onion'):
argb.port = 80
elif argb.i2p or domain.endswith('.i2p'):
proxy_type = 'i2p'
if domain.endswith('.i2p'):
argb.port = 80
elif argb.gnunet:
proxy_type = 'gnunet'
if not argb.language:
argb.language = 'en'
moved_dict = \
get_moved_accounts(base_dir, nickname, domain, 'following.txt')
pprint(moved_dict)
sys.exit()
if argb.postDomains:
if '@' not in argb.postDomains:
if '/users/' in argb.postDomains:

View File

@ -1089,7 +1089,15 @@ def _person_receive_update(base_dir: str,
print('actor updated for ' + person_json['id'])
if person_json.get('movedTo'):
new_actor = person_json['id'] + ' ' + person_json['movedTo']
prev_domain, prev_port = get_domain_from_actor(person_json['id'])
prev_domain_full = get_full_domain(prev_domain, prev_port)
prev_nickname = get_nickname_from_actor(person_json['id'])
new_domain, new_port = get_domain_from_actor(person_json['movedTo'])
new_domain_full = get_full_domain(new_domain, new_port)
new_nickname = get_nickname_from_actor(person_json['movedTo'])
new_actor = prev_nickname + '@' + prev_domain_full + ' ' + \
new_nickname + '@' + new_domain_full
refollow_str = ''
refollow_filename = base_dir + '/accounts/actors_moved.txt'
refollow_file_exists = False

51
relationships.py 100644
View File

@ -0,0 +1,51 @@
__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')
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:
for line in refollow_list:
if line.startswith(handle + ' '):
new_handle = line.split(' ')[1]
result[handle] = new_handle
break
return result