From d9336fda6efbc7ef0c2ceaecfebaf60599e0e4f3 Mon Sep 17 00:00:00 2001 From: Anon Date: Fri, 28 Oct 2022 23:58:13 -0700 Subject: [PATCH] Minor refactor --- src/yandere_bot.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/yandere_bot.py b/src/yandere_bot.py index 402c6c8..ebfa4cb 100644 --- a/src/yandere_bot.py +++ b/src/yandere_bot.py @@ -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