Moved time functions to yandereBot.py
This commit is contained in:
parent
17e80459ce
commit
6a0c38ab74
@ -1,90 +0,0 @@
|
|||||||
#! /usr/bin/env python3
|
|
||||||
|
|
||||||
# Mirai Nikki Bot a video frame posting bot for Pleroma
|
|
||||||
# Copyright (C) 2022 Anon
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
# yanlib.py is required by yandereBot.py
|
|
||||||
# This file contains functions and utilities that may be useful to external tools and programs that interface with
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------- 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()
|
|
||||||
|
|
||||||
|
|
||||||
def input_time_format(s):
|
|
||||||
return s.replace("-", "")
|
|
||||||
|
|
||||||
|
|
||||||
def humanize_time_delta(total_seconds):
|
|
||||||
m, s = divmod(int(total_seconds), 60)
|
|
||||||
h, m = divmod(m, 60)
|
|
||||||
d, h = divmod(h, 24)
|
|
||||||
return d, h, m, s
|
|
||||||
|
|
||||||
|
|
||||||
# -------------------------------- Pretty Print Functions ------------------------------------
|
|
||||||
# If value is a subclass of string, return it in parentheses (used for generating a python configuration file)
|
|
||||||
def _pp_str(v):
|
|
||||||
if issubclass(str, type(v)):
|
|
||||||
return '"{}"'.format(v)
|
|
||||||
else:
|
|
||||||
return "{}".format(v)
|
|
||||||
|
|
||||||
|
|
||||||
# Prints out a dictionary in pretty print form as valid python code.
|
|
||||||
# setting_dict should consist of string formats with key value pairs defined in setting_dict ex. '{key} {value}'.
|
|
||||||
def _pp_dict(head, setting_dict, fmt, tail):
|
|
||||||
if head:
|
|
||||||
print(head)
|
|
||||||
last_index = len(setting_dict) - 1
|
|
||||||
# i, k -> index and key value of setting_dict
|
|
||||||
for i, k in enumerate(setting_dict):
|
|
||||||
_fmt = fmt
|
|
||||||
_k = _pp_str(k)
|
|
||||||
_v = _pp_str(setting_dict[k])
|
|
||||||
# Add comma separator on all but the last value setting
|
|
||||||
if i < last_index:
|
|
||||||
_fmt += ","
|
|
||||||
print(_fmt.format(_k, _v))
|
|
||||||
if tail:
|
|
||||||
print(tail)
|
|
||||||
|
|
||||||
|
|
||||||
def pp_ordered_dict(setting, setting_dict):
|
|
||||||
_pp_dict(
|
|
||||||
"{} = OrderedDict([".format(setting),
|
|
||||||
setting_dict,
|
|
||||||
'\t({},\t{})',
|
|
||||||
"])")
|
|
||||||
|
|
||||||
|
|
||||||
def pp_dict(setting, setting_dict):
|
|
||||||
_pp_dict(
|
|
||||||
"{} = {{".format(setting),
|
|
||||||
setting_dict,
|
|
||||||
'\t{}:\t{}',
|
|
||||||
"}")
|
|
Reference in New Issue
Block a user