Minor refactor

This commit is contained in:
Anon 2022-10-28 23:58:13 -07:00
parent e2c26d5b46
commit d9336fda6e

View File

@ -21,6 +21,7 @@ import yanlib
import os
import contextlib
import fnmatch
from functools import reduce
from threading import Event
from mastodon import Mastodon, MastodonIllegalArgumentError, MastodonAPIError, MastodonVersionError
@ -161,16 +162,18 @@ class YandereBot:
if not self.settings_behavior["master_list"]:
raise MissingMasterList
list_pictures = []
# Return a list of hashes with profiles
try:
for f in self.settings_behavior["master_list"]:
add_list = get_list_of_hashes_with_profiles(f, self.settings_post, self.settings_post_default)
list_pictures.extend(add_list)
list_pictures = reduce(lambda x, y: x + y,
[get_list_of_hashes_with_profiles(
f,
self.settings_post,
self.settings_post_default)
for f in self.settings_behavior["master_list"]
])
return yanlib.get_hash_list_blacklist(list_pictures, list_blacklist, self.settings_behavior["max_size"])
except IOError as e:
print(e)
raise MissingMasterList
return yanlib.get_hash_list_blacklist(list_pictures, list_blacklist, self.settings_behavior["max_size"])
def load_picture_list(self):
list_blacklist = self.read_blacklist_files()
@ -381,11 +384,7 @@ def get_profile(hash_obj, profiles, profiles_default):
# @param profiles_default The default profile to apply
# @param callback_get_profile Callback function -> should return a single profile. Default: get_profile()
def get_list_of_hashes_with_profiles(f_name, profiles, profile_default):
r = []
for item in yanlib.get_hash_list(f_name):
post_setting = get_profile(item, profiles, profile_default)
r.append(YanBotHash(item, post_setting))
return r
return [YanBotHash(i, get_profile(i, profiles, profile_default)) for i in yanlib.get_hash_list(f_name)]
# Custom Exceptions for YandereBot