From 88991c52cbe744a7966b859deafdf319bc6278e8 Mon Sep 17 00:00:00 2001 From: Florian Kellermann Date: Mon, 9 May 2022 18:02:17 +0200 Subject: [PATCH] daily_challenge working now --- requirements.txt | 3 ++- source/.env.example | 2 +- source/daily_challenge.py | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index f51e33a..ce133da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ APScheduler~=3.9.1 SQLAlchemy~=1.4.36 pymysql==1.0.2 requests~=2.27.1 -beautifulsoup4~=4.11.1 \ No newline at end of file +beautifulsoup4~=4.11.1 +pandas~=1.4.1 \ No newline at end of file diff --git a/source/.env.example b/source/.env.example index d85e07d..3e32d24 100644 --- a/source/.env.example +++ b/source/.env.example @@ -6,4 +6,4 @@ BOT_API_KEY= DATABASE_CONNECTION=mysql+pymysql://scott:tiger@localhost/foo?check_same_thread=False # SQLite -# DATABASE_CONNECTION=sqlite:///db.db \ No newline at end of file +# DATABASE_CONNECTION=sqlite:///db.db?check_same_thread=False \ No newline at end of file diff --git a/source/daily_challenge.py b/source/daily_challenge.py index c33b432..006f8bf 100644 --- a/source/daily_challenge.py +++ b/source/daily_challenge.py @@ -10,13 +10,14 @@ __license__ = "None" import sys from apscheduler.schedulers.background import BackgroundScheduler import time +import pandas from bot import bot from db import User, session, Product -CHALLENGE_READY = "0 10 * * *" -CHALLENGE_OVER = "0 20 * * *" +CHALLENGE_READY = "0 8 * * *" +CHALLENGE_OVER = "0 22 * * *" def start_challenges(): """Start the daily challenges, read the crontag codes and send messages @@ -49,10 +50,10 @@ def send_current_event(str_event): Args: str_event (String): event to send """ - all_users = session.query(User.telegram_id).all() + all_users = pandas.DataFrame(session.query(User.telegram_id).all()) if str_event == "start": - for element in all_users: + for element in all_users["telegram_id"]: bot.send_message(chat_id=int(element), text="Todays challenge is available!\nTry /daily to give it a try :)") elif str_event == "over": for element in all_users: @@ -63,8 +64,10 @@ def send_current_event(str_event): if __name__ == "__main__": try: - test = session.query(User.telegram_id).all() - print(test) + test = pandas.DataFrame(session.query(User.telegram_id).all()) + for element in test["telegram_id"]: + print(element) + start_challenges() sys.exit(-1) except KeyboardInterrupt: