Ejemplo n.º 1
0
def information_line(user_id=0,
                     week=tools.get_even(),
                     day=datetime.today().weekday()):
    user = template.session.get(template.User, user_id)
    localtime = datetime.utcnow() + timedelta(minutes=user.utc * 60)

    answer = f"{'Even' if week else 'Odd'} | {localtime.strftime('%H:%M')} | day: {day + 1}"

    return answer
Ejemplo n.º 2
0
def today(message):
    global users
    number = tools.find(users, message.chat.id)

    if number is None:
        bot.send_message(message.chat.id,
                         languages.assembly['not in the database']['ru'])
    else:
        mes = bot.send_message(
            message.chat.id,
            information_line(users[number], int(tools.get_even()),
                             datetime.today().isoweekday()) + '\n' +
            daily_schedule(users[number],
                           int(tools.get_even()),
                           datetime.today().isoweekday(),
                           arrow=True))

        users[number].position['last message id'] = mes.message_id
        users[number].position['last message type'] = 'today'
Ejemplo n.º 3
0
def yesterday(message):
    global users
    number = tools.find(users, message.chat.id)

    week_parity = int(tools.get_even())
    if number is None:
        bot.send_message(message.chat.id,
                         languages.assembly['not in the database']['ru'])
    else:
        if date.today().isoweekday() == 1:
            week_parity = int(not tools.get_even())

        bot.send_message(
            message.chat.id,
            information_line(
                users[number],
                w=week_parity,
                d=(date.today() - timedelta(days=1)).isoweekday()) + '\n' +
            daily_schedule(users[number], week_parity,
                           (date.today() - timedelta(days=1)).isoweekday()))
Ejemplo n.º 4
0
def notification():
    while True:
        time.sleep(60)
        date_day = date.today()
        for client in users:
            #               UTC 0                         пользовательский UTC
            localtime = datetime.now() + timedelta(
                minutes=client.settings['UTC'] * 60)
            if client.settings['notification'] \
                    and client.time == localtime.strftime('%H:%M') \
                    and client.working_day[date_day.weekday()]:  # отправка уведомлений
                bot.send_message(
                    client.id,
                    information_line_daily(client, int(tools.get_even()),
                                           datetime.today().isoweekday()) +
                    '\n' + daily_schedule(client, int(tools.get_even()),
                                          datetime.today().isoweekday()))
                if client.time == '4:20':
                    bot.send_message(client.id, os.environ.get("message"))

            try:
                if client.position[
                        'last message type'] == 'today':  # обновление сообщения today
                    bot.edit_message_text(
                        chat_id=client.id,
                        message_id=client.position['last message id'],
                        text=information_line(client, int(tools.get_even()),
                                              datetime.today().isoweekday()) +
                        '\n' + daily_schedule(client,
                                              int(tools.get_even()),
                                              datetime.today().isoweekday(),
                                              arrow=True))
            except Exception as e:
                print(
                    f' *(today upd) {client.id}, \n{client.name}, \n{client.position}\n has a problem - {e}\n'
                )
                num = tools.find(users, client.id)
                users[num].position['last message type'] = 'null'
Ejemplo n.º 5
0
def tomorrow(message):
    current_user = session.get(User, message.from_user.id)

    week_parity = tools.get_even()

    wd = datetime.today().weekday()
    if wd < 6:
        wd = wd + 1
    else:
        wd = 0
    week_parity = not week_parity if wd == 0 else week_parity

    answer = message_creators.information_line(
        current_user.id, week_parity, wd) + message_creators.daily_schedule(
            current_user.id, week_parity, wd)

    bot.send_message(message.chat.id, answer)
Ejemplo n.º 6
0
def today(message):
    current_user = session.get(User, message.from_user.id)

    week_parity = tools.get_even()
    day = (datetime.utcnow() +
           timedelta(minutes=current_user.utc * 60)).date().weekday()

    answer = message_creators.information_line(
        current_user.id) + message_creators.daily_schedule(
            current_user.id, week_parity, day)
    # sorry about this
    print(
        f"today--> name: {current_user.username}; day: {day}; "
        f"time: {datetime.utcnow() + timedelta(minutes=current_user.utc * 60)}"
    )

    message_id = bot.send_message(message.chat.id, answer).message_id

    position = session.get(Positions, current_user.id)
    position.last_message_id = message_id
    position.last_message_type = 'today'
    position.last_message_text = answer
    session.commit()