Revert "Loading lists"

This reverts commit a2ebdfc1bd.
main
bashrc 2026-04-26 17:04:05 +01:00
parent c613c8ef34
commit 3491644e3a
1 changed files with 45 additions and 64 deletions

109
follow.py
View File

@ -45,8 +45,6 @@ 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:
@ -67,16 +65,12 @@ 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] = []
following_handles_str = \ try:
load_string(following_filename, with open(following_filename, 'r',
'EX: create_initial_last_seen ' + encoding='utf-8') as fp_foll:
following_filename) following_handles = fp_foll.readlines()
if following_handles_str: except OSError:
following_handles2 = following_handles_str.split('\n') print('EX: create_initial_last_seen ' + following_filename)
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
@ -92,10 +86,13 @@ 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
text = str(100) try:
save_string(text, last_seen_filename, with open(last_seen_filename, 'w+',
'EX: create_initial_last_seen 2 ' + encoding='utf-8') as fp_last:
last_seen_filename) fp_last.write(str(100))
except OSError:
print('EX: create_initial_last_seen 2 ' +
last_seen_filename)
break break
@ -245,14 +242,11 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
return [] return []
lines: list[str] = [] lines: list[str] = []
lines_str = load_string(followers_file, try:
'EX: get_follower_domains ' + followers_file) with open(followers_file, 'r', encoding='utf-8') as fp_foll:
if lines_str: lines = fp_foll.readlines()
lines2 = lines_str.split('\n') except OSError:
for line in lines2: print('EX: get_follower_domains ' + followers_file)
if not line:
continue
lines.append(line + '\n')
domains_list: list[str] = [] domains_list: list[str] = []
for handle in lines: for handle in lines:
@ -284,11 +278,12 @@ def is_follower_of_person(base_dir: str, nickname: str, domain: str,
already_following = False already_following = False
followers_str = load_string(followers_file, followers_str = ''
'EX: is_follower_of_person ' + try:
followers_file) with open(followers_file, 'r', encoding='utf-8') as fp_foll:
if followers_str is None: followers_str = fp_foll.read()
followers_str = '' except OSError:
print('EX: is_follower_of_person ' + followers_file)
if handle in followers_str: if handle in followers_str:
already_following = True already_following = True
@ -338,16 +333,11 @@ 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:
lines_str = load_string(filename, with open(filename, 'r', encoding='utf-8') as fp_unfoll:
'EX: unfollow_account ' + filename) lines = fp_unfoll.readlines()
if lines_str: except OSError:
lines2 = lines_str.split('\n') print('EX: unfollow_account ' + filename)
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:
@ -433,14 +423,11 @@ 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] = []
lines_str = load_string(filename, try:
'EX: _get_no_of_follows ' + filename) with open(filename, 'r', encoding='utf-8') as fp_foll:
if lines_str: lines = fp_foll.readlines()
lines2 = lines_str.split('\n') except OSError:
for line in lines2: print('EX: _get_no_of_follows ' + filename)
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:
@ -558,14 +545,11 @@ 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] = []
lines_str = load_string(filename, try:
'EX: get_following_feed ' + filename) with open(filename, 'r', encoding='utf-8') as fp_foll:
if lines_str: lines = fp_foll.readlines()
lines2 = lines_str.split('\n') except OSError:
for line in lines2: print('EX: get_following_feed ' + filename)
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'):
@ -647,15 +631,12 @@ def no_of_follow_requests(base_dir: str,
return 0 return 0
ctr = 0 ctr = 0
lines: list[str] = [] lines: list[str] = []
lines_str = load_string(approve_follows_filename, try:
'EX: no_of_follow_requests ' + with open(approve_follows_filename, 'r',
approve_follows_filename) encoding='utf-8') as fp_approve:
if lines_str: lines = fp_approve.readlines()
lines2 = lines_str.split('\n') except OSError:
for line in lines2: print('EX: no_of_follow_requests ' + approve_follows_filename)
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: