From a328c255afb169af50ca69bead7441a80dfb7ac1 Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 1 Sep 2023 14:42:55 +0200 Subject: [PATCH] create basic loop which checks whether a new day started --- setup.cfg | 2 +- src/remember_remember_bot/loop.py | 21 +++++++++++++++++++++ tests/test_loop.py | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/remember_remember_bot/loop.py create mode 100644 tests/test_loop.py diff --git a/setup.cfg b/setup.cfg index 29b07a8..9653582 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ where = src [options.entry_points] console_scripts = - remember-remember-bot = remember_remember_bot.cli:main + remember-remember-bot = remember_remember_bot.loop:loop [tox:tox] envlist = lint, py310 diff --git a/src/remember_remember_bot/loop.py b/src/remember_remember_bot/loop.py new file mode 100644 index 0000000..adcf13a --- /dev/null +++ b/src/remember_remember_bot/loop.py @@ -0,0 +1,21 @@ +import time +import datetime + + +def loop(): + current_day = 0 + while True: + if check_new_day(current_day): + pass + print(current_day) + current_day = update_day() + time.sleep(1) + + +def check_new_day(current_day): + if current_day == datetime.datetime.now().day: + return True + + +def update_day(): + return datetime.datetime.now().day diff --git a/tests/test_loop.py b/tests/test_loop.py new file mode 100644 index 0000000..061f8f0 --- /dev/null +++ b/tests/test_loop.py @@ -0,0 +1,8 @@ +from remember_remember_bot.loop import check_new_day, update_day + + +def test_update_day() -> None: + current_day = 0 + assert check_new_day(current_day) + current_day = update_day() + assert not check_new_day(current_day)