Loading lists

main
bashrc 2026-04-26 15:23:00 +01:00
parent feb9b3e1ff
commit a2ebdfc1bd
1 changed files with 64 additions and 45 deletions

109
follow.py
View File

@ -45,6 +45,8 @@ from session import get_json
from session import get_json_valid 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 save_string
def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
@ -65,12 +67,16 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
if not os.path.isdir(last_seen_dir): if not os.path.isdir(last_seen_dir):
os.mkdir(last_seen_dir) os.mkdir(last_seen_dir)
following_handles: list[str] = [] following_handles: list[str] = []
try: following_handles_str = \
with open(following_filename, 'r', load_string(following_filename,
encoding='utf-8') as fp_foll: 'EX: create_initial_last_seen ' +
following_handles = fp_foll.readlines() following_filename)
except OSError: if following_handles_str:
print('EX: create_initial_last_seen ' + following_filename) following_handles2 = following_handles_str.split('\n')
for follhandle in following_handles2:
if not follhandle:
continue
following_handles.append(follhandle + '\n')
for handle in following_handles: for handle in following_handles:
if '#' in handle: if '#' in handle:
continue continue
@ -86,13 +92,10 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
last_seen_dir + '/' + actor.replace('/', '#') + '.txt' last_seen_dir + '/' + actor.replace('/', '#') + '.txt'
if os.path.isfile(last_seen_filename): if os.path.isfile(last_seen_filename):
continue continue
try: text = str(100)
with open(last_seen_filename, 'w+', save_string(text, last_seen_filename,
encoding='utf-8') as fp_last: 'EX: create_initial_last_seen 2 ' +
fp_last.write(str(100)) last_seen_filename)
except OSError:
print('EX: create_initial_last_seen 2 ' +
last_seen_filename)
break break
@ -242,11 +245,14 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
return [] return []
lines: list[str] = [] lines: list[str] = []
try: lines_str = load_string(followers_file,
with open(followers_file, 'r', encoding='utf-8') as fp_foll: 'EX: get_follower_domains ' + followers_file)
lines = fp_foll.readlines() if lines_str:
except OSError: lines2 = lines_str.split('\n')
print('EX: get_follower_domains ' + followers_file) for line in lines2:
if not line:
continue
lines.append(line + '\n')
domains_list: list[str] = [] domains_list: list[str] = []
for handle in lines: for handle in lines:
@ -278,12 +284,11 @@ def is_follower_of_person(base_dir: str, nickname: str, domain: str,
already_following = False already_following = False
followers_str = '' followers_str = load_string(followers_file,
try: 'EX: is_follower_of_person ' +
with open(followers_file, 'r', encoding='utf-8') as fp_foll: followers_file)
followers_str = fp_foll.read() if followers_str is None:
except OSError: followers_str = ''
print('EX: is_follower_of_person ' + followers_file)
if handle in followers_str: if handle in followers_str:
already_following = True already_following = True
@ -333,11 +338,16 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
' is not in ' + filename) ' is not in ' + filename)
return False return False
lines: list[str] = [] lines: list[str] = []
try:
with open(filename, 'r', encoding='utf-8') as fp_unfoll: lines_str = load_string(filename,
lines = fp_unfoll.readlines() 'EX: unfollow_account ' + filename)
except OSError: if lines_str:
print('EX: unfollow_account ' + filename) lines2 = lines_str.split('\n')
for line in lines2:
if not line:
continue
lines.append(line + '\n')
if lines: if lines:
try: try:
with open(filename, 'w+', encoding='utf-8') as fp_unfoll: with open(filename, 'w+', encoding='utf-8') as fp_unfoll:
@ -423,11 +433,14 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
return 0 return 0
ctr = 0 ctr = 0
lines: list[str] = [] lines: list[str] = []
try: lines_str = load_string(filename,
with open(filename, 'r', encoding='utf-8') as fp_foll: 'EX: _get_no_of_follows ' + filename)
lines = fp_foll.readlines() if lines_str:
except OSError: lines2 = lines_str.split('\n')
print('EX: _get_no_of_follows ' + filename) for line in lines2:
if not line:
continue
lines.append(line + '\n')
if lines: if lines:
for line in lines: for line in lines:
if '#' in line: if '#' in line:
@ -545,11 +558,14 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
page_ctr = 0 page_ctr = 0
total_ctr = 0 total_ctr = 0
lines: list[str] = [] lines: list[str] = []
try: lines_str = load_string(filename,
with open(filename, 'r', encoding='utf-8') as fp_foll: 'EX: get_following_feed ' + filename)
lines = fp_foll.readlines() if lines_str:
except OSError: lines2 = lines_str.split('\n')
print('EX: get_following_feed ' + filename) for line in lines2:
if not line:
continue
lines.append(line + '\n')
for line in lines: for line in lines:
if '#' not in line: if '#' not in line:
if '@' in line and not line.startswith('http'): if '@' in line and not line.startswith('http'):
@ -631,12 +647,15 @@ def no_of_follow_requests(base_dir: str,
return 0 return 0
ctr = 0 ctr = 0
lines: list[str] = [] lines: list[str] = []
try: lines_str = load_string(approve_follows_filename,
with open(approve_follows_filename, 'r', 'EX: no_of_follow_requests ' +
encoding='utf-8') as fp_approve: approve_follows_filename)
lines = fp_approve.readlines() if lines_str:
except OSError: lines2 = lines_str.split('\n')
print('EX: no_of_follow_requests ' + approve_follows_filename) for line in lines2:
if not line:
continue
lines.append(line + '\n')
if lines: if lines:
if follow_type == "onion": if follow_type == "onion":
for file_line in lines: for file_line in lines: