From e8190a500d260b09050874d3e095cb968fb2ed8b Mon Sep 17 00:00:00 2001 From: Simple_Not <44047940+moonbaseDelta@users.noreply.github.com> Date: Sun, 16 Jul 2023 01:50:12 +1000 Subject: [PATCH] fixxed pipisa --- __init__.py | 0 handlers/pipisa.py | 10 +++-- pipisa_functions/__init__.py | 1 + pipisa_functions/pipisa_time.py | 76 +++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 __init__.py create mode 100644 pipisa_functions/__init__.py create mode 100644 pipisa_functions/pipisa_time.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/handlers/pipisa.py b/handlers/pipisa.py index 67d715f..a32abba 100644 --- a/handlers/pipisa.py +++ b/handlers/pipisa.py @@ -6,6 +6,7 @@ import random from random import randint import datetime from dicktxt import ForReadDict +from pipisa_functions import pipisa_time #### https://docs.python-arango.com/en/main/ @@ -60,10 +61,13 @@ async def up_dick(message: types.Message): user = candidate_cursor.pop() - last_time = datetime.datetime.strptime(user['datetimes'], '%Y-%m-%d %H:%M:%S') - time_to_grow = datetime.datetime.now().replace(hour=14, minute=8, second=8, microsecond=0) #+ datetime.timedelta(days=0) + # last_time = datetime.datetime.strptime(user['datetimes'], '%Y-%m-%d %H:%M:%S') + # time_to_grow = datetime.datetime.now().replace(hour=14, minute=8, second=8, microsecond=0) #+ datetime.timedelta(days=0) - if (time_to_grow - last_time).total_seconds() > 0: + + + # if (time_to_grow - last_time).total_seconds() > 0: + if pipisa_time.rolltime(check_datetime=user['datetimes']): # пришло время крутить!! updetedDick = user["dick_size"] + numb diff --git a/pipisa_functions/__init__.py b/pipisa_functions/__init__.py new file mode 100644 index 0000000..f46c5e6 --- /dev/null +++ b/pipisa_functions/__init__.py @@ -0,0 +1 @@ +from . import pipisa_time \ No newline at end of file diff --git a/pipisa_functions/pipisa_time.py b/pipisa_functions/pipisa_time.py new file mode 100644 index 0000000..7da73e5 --- /dev/null +++ b/pipisa_functions/pipisa_time.py @@ -0,0 +1,76 @@ + +import unittest +import datetime + + + +def rolltime(check_datetime , curr_time=datetime.datetime.now()): + + last_time = datetime.datetime.strptime(check_datetime, '%Y-%m-%d %H:%M:%S') + time_to_grow = curr_time.replace(hour=14, minute=8, second=8, microsecond=0) #+ datetime.timedelta(days=0) + + timediff = (time_to_grow - last_time).total_seconds() + + # print(f'\tlast_time : {last_time}') + # print(f'\ttime_to_grow : {time_to_grow}') + # print(f'\tcurr_time : {curr_time.strftime("%Y-%m-%d %H:%M:%S")}') + # print(f'\t\tsecs diff : {timediff}') + + if timediff > 86400 or curr_time > time_to_grow: + return True + else: + return False + + + +class TestPipisa(unittest.TestCase): + def test_very_long_ago(self): + self.assertEqual(rolltime('2021-10-11 23:44:00'), True, "Пиписа прокручена очень давно. Очевидный прокрут") + + def test_just_after(self): + self.assertEqual(rolltime( + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0).strftime('%Y-%m-%d %H:%M:%S') + ), False, "Попытка крутить когда старый прокрут был через 1 минуту после сегодняшнего обновления роллов. Фейл.") + + def test_yesterdayroll(self): + self.assertEqual( + rolltime( + ( + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(days=1) + ).strftime('%Y-%m-%d %H:%M:%S'), + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) + ), True, "Крутилась вчера через минуту после обновления роллов. Должно пропускать ") + + + def test_hour_before_roll(self): + self.assertEqual( + rolltime( + ( + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=1) + ).strftime('%Y-%m-%d %H:%M:%S'), + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) + ), True, "Крутилась последний раз за час до прокрута. Надо разрешать заново!") + + def test_after_midnight(self): + self.assertEqual( + rolltime( + ( + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=14) + ).strftime('%Y-%m-%d %H:%M:%S'), + datetime.datetime.now().replace(hour=0, minute=11, second=8, microsecond=0) + ), False, "Где-то ночью прокручивается повторно. Фейл.") + + def test_before_midnight(self): + self.assertEqual( + rolltime( + ( + datetime.datetime.now().replace(hour=14, minute=9, second=8, microsecond=0) - datetime.timedelta(hours=15) + ).strftime('%Y-%m-%d %H:%M:%S'), + datetime.datetime.now().replace(hour=0, minute=11, second=8, microsecond=0) - datetime.timedelta(hours=15) + ), False, "Где-то ночью прокручивается повторно. Фейл.") + + + + +if __name__ == "__main__": + unittest.main() \ No newline at end of file