Revert "Function to load lists"

This reverts commit 521e5d0f80.
main
bashrc 2026-04-26 17:03:47 +01:00
parent 521e5d0f80
commit c613c8ef34
2 changed files with 58 additions and 36 deletions

15
data.py
View File

@ -37,21 +37,6 @@ def load_string(filename: str, exception_text: str) -> str:
return None return None
def load_list(filename: str, exception_text: str) -> str:
"""Loads a list from file
This is used to replace readlines
"""
lines: list[str] = []
lines_str = load_string(filename, exception_text)
if lines_str:
lines2 = lines_str.split('\n')
for line in lines2:
if not line:
continue
lines.append(line + '\n')
return lines
def save_string(text: str, filename: str, exception_text: str) -> bool: def save_string(text: str, filename: str, exception_text: str) -> bool:
"""Saves a string to file """Saves a string to file
""" """

View File

@ -46,7 +46,6 @@ 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 load_list
from data import save_string from data import save_string
@ -67,10 +66,17 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
last_seen_dir = account_dir + '/lastseen' last_seen_dir = account_dir + '/lastseen'
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] = []
load_list(following_filename, following_handles_str = \
load_string(following_filename,
'EX: create_initial_last_seen ' + 'EX: create_initial_last_seen ' +
following_filename) following_filename)
if following_handles_str:
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
@ -238,9 +244,15 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
if not os.path.isfile(followers_file): if not os.path.isfile(followers_file):
return [] return []
lines: list[str] = \ lines: list[str] = []
load_list(followers_file, lines_str = load_string(followers_file,
'EX: get_follower_domains ' + followers_file) 'EX: get_follower_domains ' + followers_file)
if lines_str:
lines2 = lines_str.split('\n')
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:
@ -325,9 +337,16 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
print('DEBUG: handle to unfollow ' + handle_to_unfollow + print('DEBUG: handle to unfollow ' + handle_to_unfollow +
' is not in ' + filename) ' is not in ' + filename)
return False return False
lines: list[str] = \ lines: list[str] = []
load_list(filename,
lines_str = load_string(filename,
'EX: unfollow_account ' + filename) 'EX: unfollow_account ' + filename)
if lines_str:
lines2 = lines_str.split('\n')
for line in lines2:
if not line:
continue
lines.append(line + '\n')
if lines: if lines:
try: try:
@ -413,9 +432,15 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
if not os.path.isfile(filename): if not os.path.isfile(filename):
return 0 return 0
ctr = 0 ctr = 0
lines: list[str] = \ lines: list[str] = []
load_list(filename, lines_str = load_string(filename,
'EX: _get_no_of_follows ' + filename) 'EX: _get_no_of_follows ' + filename)
if lines_str:
lines2 = lines_str.split('\n')
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:
@ -532,9 +557,15 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
curr_page = 1 curr_page = 1
page_ctr = 0 page_ctr = 0
total_ctr = 0 total_ctr = 0
lines: list[str] = \ lines: list[str] = []
load_list(filename, lines_str = load_string(filename,
'EX: get_following_feed ' + filename) 'EX: get_following_feed ' + filename)
if lines_str:
lines2 = lines_str.split('\n')
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'):
@ -615,10 +646,16 @@ def no_of_follow_requests(base_dir: str,
if not os.path.isfile(approve_follows_filename): if not os.path.isfile(approve_follows_filename):
return 0 return 0
ctr = 0 ctr = 0
lines: list[str] = \ lines: list[str] = []
load_list(approve_follows_filename, lines_str = load_string(approve_follows_filename,
'EX: no_of_follow_requests ' + 'EX: no_of_follow_requests ' +
approve_follows_filename) approve_follows_filename)
if lines_str:
lines2 = lines_str.split('\n')
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: