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
|
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
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
79
follow.py
79
follow.py
|
|
@ -46,6 +46,7 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,17 +67,10 @@ 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] = \
|
||||||
following_handles_str = \
|
load_list(following_filename,
|
||||||
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
|
||||||
|
|
@ -244,15 +238,9 @@ 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] = \
|
||||||
lines_str = load_string(followers_file,
|
load_list(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:
|
||||||
|
|
@ -337,16 +325,9 @@ 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:
|
||||||
|
|
@ -432,15 +413,9 @@ 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] = \
|
||||||
lines_str = load_string(filename,
|
load_list(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:
|
||||||
|
|
@ -557,15 +532,9 @@ 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] = \
|
||||||
lines_str = load_string(filename,
|
load_list(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'):
|
||||||
|
|
@ -646,16 +615,10 @@ 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] = \
|
||||||
lines_str = load_string(approve_follows_filename,
|
load_list(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:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue