mirror of https://gitlab.com/bashrc2/epicyon
Function to load lists
parent
a2ebdfc1bd
commit
521e5d0f80
15
data.py
15
data.py
|
|
@ -37,6 +37,21 @@ def load_string(filename: str, exception_text: str) -> str:
|
|||
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:
|
||||
"""Saves a string to file
|
||||
"""
|
||||
|
|
|
|||
79
follow.py
79
follow.py
|
|
@ -46,6 +46,7 @@ from session import get_json_valid
|
|||
from session import post_json
|
||||
from followerSync import remove_followers_sync
|
||||
from data import load_string
|
||||
from data import load_list
|
||||
from data import save_string
|
||||
|
||||
|
||||
|
|
@ -66,17 +67,10 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
|
|||
last_seen_dir = account_dir + '/lastseen'
|
||||
if not os.path.isdir(last_seen_dir):
|
||||
os.mkdir(last_seen_dir)
|
||||
following_handles: list[str] = []
|
||||
following_handles_str = \
|
||||
load_string(following_filename,
|
||||
'EX: create_initial_last_seen ' +
|
||||
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')
|
||||
following_handles: list[str] = \
|
||||
load_list(following_filename,
|
||||
'EX: create_initial_last_seen ' +
|
||||
following_filename)
|
||||
for handle in following_handles:
|
||||
if '#' in handle:
|
||||
continue
|
||||
|
|
@ -244,15 +238,9 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
|
|||
if not os.path.isfile(followers_file):
|
||||
return []
|
||||
|
||||
lines: list[str] = []
|
||||
lines_str = load_string(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')
|
||||
lines: list[str] = \
|
||||
load_list(followers_file,
|
||||
'EX: get_follower_domains ' + followers_file)
|
||||
|
||||
domains_list: list[str] = []
|
||||
for handle in lines:
|
||||
|
|
@ -337,16 +325,9 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
|
|||
print('DEBUG: handle to unfollow ' + handle_to_unfollow +
|
||||
' is not in ' + filename)
|
||||
return False
|
||||
lines: list[str] = []
|
||||
|
||||
lines_str = load_string(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')
|
||||
lines: list[str] = \
|
||||
load_list(filename,
|
||||
'EX: unfollow_account ' + filename)
|
||||
|
||||
if lines:
|
||||
try:
|
||||
|
|
@ -432,15 +413,9 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
|
|||
if not os.path.isfile(filename):
|
||||
return 0
|
||||
ctr = 0
|
||||
lines: list[str] = []
|
||||
lines_str = load_string(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')
|
||||
lines: list[str] = \
|
||||
load_list(filename,
|
||||
'EX: _get_no_of_follows ' + filename)
|
||||
if lines:
|
||||
for line in lines:
|
||||
if '#' in line:
|
||||
|
|
@ -557,15 +532,9 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
|
|||
curr_page = 1
|
||||
page_ctr = 0
|
||||
total_ctr = 0
|
||||
lines: list[str] = []
|
||||
lines_str = load_string(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')
|
||||
lines: list[str] = \
|
||||
load_list(filename,
|
||||
'EX: get_following_feed ' + filename)
|
||||
for line in lines:
|
||||
if '#' not in line:
|
||||
if '@' in line and not line.startswith('http'):
|
||||
|
|
@ -646,16 +615,10 @@ def no_of_follow_requests(base_dir: str,
|
|||
if not os.path.isfile(approve_follows_filename):
|
||||
return 0
|
||||
ctr = 0
|
||||
lines: list[str] = []
|
||||
lines_str = load_string(approve_follows_filename,
|
||||
'EX: no_of_follow_requests ' +
|
||||
approve_follows_filename)
|
||||
if lines_str:
|
||||
lines2 = lines_str.split('\n')
|
||||
for line in lines2:
|
||||
if not line:
|
||||
continue
|
||||
lines.append(line + '\n')
|
||||
lines: list[str] = \
|
||||
load_list(approve_follows_filename,
|
||||
'EX: no_of_follow_requests ' +
|
||||
approve_follows_filename)
|
||||
if lines:
|
||||
if follow_type == "onion":
|
||||
for file_line in lines:
|
||||
|
|
|
|||
Loading…
Reference in New Issue