This commit is contained in:
Linus E 2022-05-09 18:37:43 +02:00
commit 768ecb1f2a
2 changed files with 56 additions and 20 deletions

View File

@ -14,12 +14,16 @@ import os
import re
import sys
import datetime as dt
import time
import sqlalchemy
import telebot
import pandas as pd
from dotenv import load_dotenv
from telebot import types
from random import randrange
from apscheduler.schedulers.background import BackgroundScheduler
import pandas
from db import User, session, Product
from fetcher import *
@ -29,6 +33,7 @@ from db import Score
load_dotenv(dotenv_path='.env') # load environment variables
BOT_VERSION = "0.0.1" # version of bot
UPDATE_PRODUCT = "0 1 * * *"
bot = telebot.TeleBot(os.getenv('BOT_API_KEY'))
@ -100,7 +105,7 @@ def send_help(message):
"/scoreboard get scoreboard\n"
"/changename change your name\n"
"/challenge get todays challenge\n"
"/guess make guess for today")
"/daily make guess for today")
bot.reply_to(message, help_message, parse_mode='MARKDOWN')
@ -306,23 +311,6 @@ def send_challenge(message):
bot.reply_to(message, "Challenge not implemented yet")
@bot.message_handler(commands=['guess', 'Guess'])
def send_guess(message):
"""let user guess the price of the product
Args:
message (Message): Message from telegram user, here /guess
Returns:
None: None
Raises:
None: None
"""
bot.reply_to(message, "Guess not implemented yet")
@bot.message_handler(commands=['changename', 'Changename'])
def change_name(message):
"""change user name
@ -341,6 +329,40 @@ def change_name(message):
bot.reply_to(message, "type new name (else type \"cancel\"):")
bot.register_next_step_handler(message, change_name_setter)
@bot.message_handler(commands=['daily', 'Daily'])
def daily_message(message):
"""change user name
Args:
message (Message): Message from telegram user, here /changename
Returns:
None: None
Raises:
None: None
"""
user_id = int(message.from_user.id)
bot.send_message(chat_id = user_id, text="Welcome to todays challenge!\n"
"As soon as the picture loads\n"
"you will have 35 seconds to send\n"
"your price guess\n")
time.sleep(2)
bot.send_message(chat_id = user_id, text="Lets Go!")
time.sleep(1)
for i in range(3):
iteration = 3-i
bot.send_message(chat_id=user_id, text=str(iteration))
iteration-=1
time.sleep(1)
def change_name_setter(message):
"""change user name
@ -496,8 +518,22 @@ def main_loop():
Raises:
None: None
"""
product_split = UPDATE_PRODUCT.split(" ")
my_scheduler = BackgroundScheduler()
my_scheduler.add_job(get_todays_product, 'cron'\
,day_of_week = product_split[4]\
,hour= product_split[1]\
,minute = product_split[0]\
,month= product_split[3]\
,day=product_split[2])
bot.infinity_polling()
def get_todays_product():
"""Setting product for this day
"""
print(pandas.DataFrame(session.query(Product.price,Product.image_link).all()))
if __name__ == '__main__':
try:

View File

@ -56,8 +56,8 @@ def send_current_event(str_event):
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:
bot.send_message(chat_id=int(element), text="Todays challenge is over!\nThe price was:\nCheck the /scoreboard to see the leaderboard!")
for element in all_users["telegram_id"]:
bot.send_message(chat_id=int(element), text="Todays challenge is over!\nCheck the /scoreboard to see the leaderboard!")
else:
sys.exit(-1)