Format Python code with psf/black push

github-actions 2 years ago
parent a1af23179d
commit 5cb8d73015

@ -110,13 +110,20 @@ class IndexData:
def has_indexes(self, user_id):
try:
return len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}"))) > 0
return (
len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}"))) > 0
)
except Exception:
return False
def has_search_indexes(self, user_id):
try:
return len(os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search"))) > 0
return (
len(
os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search"))
)
> 0
)
except Exception:
return False
@ -125,7 +132,9 @@ class IndexData:
self.queryable_index = index
# Create a folder called "indexes/{USER_ID}" if it doesn't exist already
Path(f"{EnvService.save_path()}/indexes/{user_id}").mkdir(parents=True, exist_ok=True)
Path(f"{EnvService.save_path()}/indexes/{user_id}").mkdir(
parents=True, exist_ok=True
)
# Save the index to file under the user id
file = f"{file_name}_{date.today().month}_{date.today().day}"
# If file is > 93 in length, cut it off to 93
@ -145,8 +154,12 @@ class IndexData:
# First, clear all the files inside it
for file in os.listdir(EnvService.find_shared_file(f"indexes/{user_id}")):
os.remove(EnvService.find_shared_file(f"indexes/{user_id}/{file}"))
for file in os.listdir(EnvService.find_shared_file(f"indexes/{user_id}_search")):
os.remove(EnvService.find_shared_file(f"indexes/{user_id}_search/{file}"))
for file in os.listdir(
EnvService.find_shared_file(f"indexes/{user_id}_search")
):
os.remove(
EnvService.find_shared_file(f"indexes/{user_id}_search/{file}")
)
except Exception:
traceback.print_exc()
@ -792,7 +805,9 @@ class Index_handler:
)
# Save the composed index
tree_index.save_to_disk(EnvService.save_path() / "indexes" / str(user_id) / name)
tree_index.save_to_disk(
EnvService.save_path() / "indexes" / str(user_id) / name
)
self.index_storage[user_id].queryable_index = tree_index
@ -822,7 +837,9 @@ class Index_handler:
name = f"composed_index_{date.today().month}_{date.today().day}.json"
# Save the composed index
simple_index.save_to_disk(EnvService.save_path() / "indexes" / str(user_id) / name)
simple_index.save_to_disk(
EnvService.save_path() / "indexes" / str(user_id) / name
)
self.index_storage[user_id].queryable_index = simple_index
try:

@ -21,7 +21,11 @@ from sqlitedict import SqliteDict
try:
print("Attempting to retrieve the settings DB")
SETTINGS_DB = SqliteDict(f"{EnvService.save_path()}/main_db.sqlite", tablename="settings", autocommit=True)
SETTINGS_DB = SqliteDict(
f"{EnvService.save_path()}/main_db.sqlite",
tablename="settings",
autocommit=True,
)
print("Retrieved the settings DB")
except Exception as e:
print("Failed to retrieve the settings DB. The bot is terminating.")

@ -64,7 +64,10 @@ class Search:
file = f"{query[:20]}_{date.today().month}_{date.today().day}"
index.save_to_disk(
EnvService.save_path() / "indexes" / f"{str(user_id)}_search" / f"{file}.json"
EnvService.save_path()
/ "indexes"
/ f"{str(user_id)}_search"
/ f"{file}.json"
)
def build_search_started_embed(self):

@ -42,7 +42,7 @@ class EnvService:
return app_relative
return Path.cwd()
@staticmethod
def save_path():
share_dir = os.getenv("SHARE_DIR")

Loading…
Cancel
Save