Compare commits

..

3 Commits

Author SHA1 Message Date
e2c26d5b46 Minor refactor 2022-10-28 20:26:14 -07:00
42ee67a107 Refactored to use lambda expressions 2022-10-28 20:25:31 -07:00
408d766d6d Added log and misc. files 2022-10-28 20:23:37 -07:00
3 changed files with 27 additions and 31 deletions

7
.gitignore vendored
View File

@ -2,6 +2,7 @@
/rsc*/
/md5/
/src/cfg*.py
/log.txt
# Virtual environment
/venv*
@ -18,8 +19,9 @@
/notes.txt
/compile.sh
/upload.sh
/balance_*.csv
/balance.ods
/balance*.csv
/balance*.ods
/default*.csv
/DEFAULT.csv
/generate_random.sh
/print_1_txt.sh
@ -32,3 +34,4 @@
/profile/
/gnu_header.txt
/backup*
/resum_default.sh

View File

@ -165,7 +165,7 @@ class YandereBot:
# 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, get_profile)
add_list = get_list_of_hashes_with_profiles(f, self.settings_post, self.settings_post_default)
list_pictures.extend(add_list)
except IOError as e:
print(e)
@ -325,6 +325,8 @@ class YandereBot:
# [BEGIN THE PROGRAM]
def prime_bot(self):
if self.primed:
return
self.load_picture_list()
self.validate_post_settings()
if not self.debug_mode:
@ -332,9 +334,7 @@ class YandereBot:
self.login()
self.primed = True
def start(self, delay=0):
# Prime bot if not already primed.
if not self.primed:
def start(self):
self.prime_bot()
# Begin posting
@ -380,16 +380,11 @@ def get_profile(hash_obj, profiles, profiles_default):
# @param profiles List of profiles -> self.settings_post
# @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, profiles_default, callback_get_profile):
def get_list_of_hashes_with_profiles(f_name, profiles, profile_default):
r = []
with open(f_name, "r") as f:
for _line in f:
line = _line.strip()
if not yanlib.is_valid_hash(line):
continue
hash_obj = yanlib.HashObject(line)
post_setting = callback_get_profile(hash_obj, profiles, profiles_default)
r.append(YanBotHash(hash_obj, post_setting))
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

View File

@ -21,9 +21,6 @@
# yandereBot, or manipulate hash files in some way. Typically instantiating a yandereBot object is unnecessary for this.
import os
import datetime
import shutil
import contextlib
# Requires properly formatted MD5 checksum lines.
@ -75,33 +72,34 @@ class HashObject:
# Checking for the binary character when comparing hash string is usually overkill since the CoreUtils package reads
# files in binary mode regardless of whether the -b switch is passed.
# It is included here since it may be useful for some other applications besides the bot.
def is_matching_atter_binary(v_list, v_hash, v_atter):
atter_bin = "get_binary_char"
def is_matching_atter_binary(v_list, v_hash, callback):
return next(
(x for x in v_list if
getattr(v_hash, v_atter)() == getattr(x, v_atter)() and
getattr(v_hash, atter_bin)() == getattr(x, atter_bin)()
callback(v_hash) == callback(x) and
v_hash.get_binary_char() == x.get_binary_char()
), None)
def is_matching_atter(v_list, v_hash, v_atter):
return next((x for x in v_list if getattr(v_hash, v_atter)() == getattr(x, v_atter)()), None)
def is_matching_atter(v_list, v_hash, callback):
return next(
(x for x in v_list if
callback(v_hash) == callback(x)
), None)
def get_matching(v_list, v_hash, atter, match_bin=False):
return is_matching_atter(v_list, v_hash, atter) if not match_bin else is_matching_atter_binary(v_list, v_hash, atter)
def get_matching(v_list, v_hash, callback, match_bin=False):
return is_matching_atter(v_list, v_hash, callback) if not match_bin else is_matching_atter_binary(v_list, v_hash, callback)
def get_matching_hash_in_list(v_list, v_hash, match_bin=False):
return get_matching(v_list, v_hash, "get_hash_string", match_bin)
return get_matching(v_list, v_hash, lambda x: x.get_hash_string(), match_bin)
def get_matching_path_in_list(v_list, v_hash, match_bin=False):
return get_matching(v_list, v_hash, "get_hash_path", match_bin)
return get_matching(v_list, v_hash, lambda x: x.get_hash_path(), match_bin)
def get_matching_full_string_in_list(v_list, v_hash, match_bin=False):
return get_matching(v_list, v_hash, "get_full_string", match_bin)
return get_matching(v_list, v_hash, lambda x: x.get_full_string(), match_bin)
# ---------------------------- HASH LIST FUNCTIONS --------------------------------------------