F
F
Fallerwood2021-06-26 00:22:47
Python
Fallerwood, 2021-06-26 00:22:47

Is it possible to make a notification system in a telegram bot in Python, by time?

I want to teach the bot to send notifications to the user about his record regarding the time, but I don’t know how to do this and I can’t find anything on the Internet.
Library: pytelegrambotapi
If someone has experience please help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
balak_in, 2021-06-26
@Fallerwood

To add days/hours/minutes to dates, you can use:
1. To add a date/time to the current value:

from datetime import timedelta, datetime, timezone

def minus_week():
    offset = timezone(timedelta(hours=3))  # Московское время
    now = datetime.now(offset)  # Текущая дата
    min_week = now + timedelta(7)  # Плюс одна неделя (7 дней)
    day = str(min_week.day)  # Получение значения дня
    month = str(min_week.month)  # Получение месяца
    if min_week.day < 10:
        day = f'0{min_week.day}'  #Чтобы день выводился было "09" а не "9"
    if min_week.month < 10:
        month = f'0{min_week.month}'
    result = f'{month}-{day}'
    return result   # Возвращает время в виде "06-26"

2. Delayed sending of daily messages:
# Функция для отправки сообщения с инфой
def send_stats():
    def send_stat():
        bot.send_message(chat_id, 'Мое сообщение')
    schedule.every().day.at('23:55').do(send_stat)

    while True:
        schedule.run_pending()
        time.sleep(5)

L
lil.fxrrx, 2021-06-26
@mxrdxfxrrx

Count the time of the posted entry using any time module (time, datetime, pendulum)
Determine the desired time, count the {time of the appearance of the entry} - {the desired time}, and display it as a message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question