Removed yanlib.py as dependency

This commit is contained in:
Anon 2022-08-27 01:43:31 -07:00
parent e98d96d85b
commit 05a09a2205

View File

@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import yanlib
import os import os
import datetime import datetime
import contextlib import contextlib
@ -137,7 +135,7 @@ class YandereBot:
dateNextSelection = None dateNextSelection = None
# YandereBot.__init__() # YandereBot.__init__()
# @param cfg A dynamically loaded python module. See yanlib.module_load() for an example # @param cfg A dynamically loaded python module
# @param debug_mode Should the bot run in debug mode (do not sign in or post to Pleroma) # @param debug_mode Should the bot run in debug mode (do not sign in or post to Pleroma)
# prime_bot Should the bot immediately prime itself (configure picture list and login, but don't post) # prime_bot Should the bot immediately prime itself (configure picture list and login, but don't post)
def __init__(self, cfg, debug_mode=False, prime_bot=True): def __init__(self, cfg, debug_mode=False, prime_bot=True):
@ -209,7 +207,7 @@ class YandereBot:
profile, frame, nsfw profile, frame, nsfw
)) ))
print("Path:", path) print("Path:", path)
next_selection_seconds = max(0, int(yanlib.time_diff_seconds(date_next_selection, date_selection))) next_selection_seconds = max(0, int(time_diff_seconds(date_next_selection, date_selection)))
print("Selection time: {}".format( print("Selection time: {}".format(
date_selection.strftime(self.settings_time["long_date_format"])) ) date_selection.strftime(self.settings_time["long_date_format"])) )
print("Next selection time: {} ({} seconds)".format( print("Next selection time: {} ({} seconds)".format(
@ -344,11 +342,11 @@ class YandereBot:
def schedule_next_post(self): def schedule_next_post(self):
self.dateSelection = self.dateNextSelection self.dateSelection = self.dateNextSelection
self.dateNextSelection = yanlib.time_add_seconds(self.dateSelection, self.settings_behavior["sleep_seconds"]) self.dateNextSelection = time_add_seconds(self.dateSelection, self.settings_behavior["sleep_seconds"])
# Will wait between the current time and the time of next selection # Will wait between the current time and the time of next selection
def wait_future_time(self): def wait_future_time(self):
seconds = yanlib.time_diff_seconds(self.dateNextSelection, datetime.datetime.now()) seconds = time_diff_seconds(self.dateNextSelection, datetime.datetime.now())
self.eventSleep.wait(max(0, seconds)) self.eventSleep.wait(max(0, seconds))
# [BEGIN THE PROGRAM] # [BEGIN THE PROGRAM]
@ -370,8 +368,8 @@ class YandereBot:
return 1 return 1
start_time = self.dateSelection start_time = self.dateSelection
delay_seconds = max(yanlib.time_diff_seconds(self.dateNextSelection, start_time) + delay, delay) delay_seconds = max(time_diff_seconds(self.dateNextSelection, start_time) + delay, delay)
delay_time = yanlib.time_add_seconds(start_time, delay_seconds) delay_time = time_add_seconds(start_time, delay_seconds)
# Print the first image in the list if a delay or pretimer is set # Print the first image in the list if a delay or pretimer is set
if delay_seconds: if delay_seconds:
@ -416,6 +414,14 @@ class YandereBot:
if self.can_post(): if self.can_post():
self.wait_future_time() self.wait_future_time()
# ------------------------------- TIME FUNCTIONS ---------------------------------------------
def time_add_seconds(dt, seconds):
return dt + datetime.timedelta(0, seconds)
def time_diff_seconds(d1, d2):
return (d1-d2).total_seconds()
# Custom Exceptions for YandereBot # Custom Exceptions for YandereBot
class Debug(Exception): class Debug(Exception):