import cfg
import telebot
import threading
import time
import random
bot = telebot.TeleBot(cfg.token)
@bot.message_handler(commands=["cmd1"])
def task(message):
bot.send_message(message.chat.id, "Хорошо, я начинаю выполнять задание.")
thread = threading.Thread(target=do_task, args=(message.chat.id,))
thread.start()
def do_task(chat_id):
t = random.randint(1,5)
time.sleep(t)
bot.send_message(chat_id, f"Я закончил задание за {t} секунд.")
bot.polling()
import paramiko
# создаем объект SSH клиента
ssh = paramiko.SSHClient()
# автоматически добавляем хост в список известных хостов
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# подключаемся к серверу
ssh.connect('192.168.0.210', username='root', password='')
# выполнение команды
stdin, stdout, stderr = ssh.exec_command('uname -a')
# вывод результатов
print(stdout.read().decode())
# закрываем соединение
ssh.close()
Linux NAS 5.10.0-23-amd64 #1 SMP Debian 5.10.179-1 (2023-05-12) x86_64 GNU/Linux
:local today [:put [/system clock get date]]
:local yesterday [:put [/system clock get date]]
:local day-before-yesterday [:put [/system clock get date]]
# вычисляем вчерашнюю дату
:for i from=1 to=86400 do={
:set $yesterday [/system clock set date=($today-$i)]
:if ($yesterday = $today) do={
:set $yesterday [/system clock set date=($today-$i-1)]
:put ("Yesterday: " . [:pick $yesterday 4 6] . "-" . [:pick $yesterday 0 3] . "-" . [:pick $yesterday 7 10])
:put ("")
:put ("Day before yesterday: " . [:pick $day-before-yesterday 4 6] . "-" . [:pick $day-before-yesterday 0 3] . "-" . [:pick $day-before-yesterday 7 10])
:return
}
}
# вычисляем позавчерашнюю дату
:for i from=2 to=172800 do={
:set $day-before-yesterday [/system clock set date=($today-$i)]
:if ($day-before-yesterday = $yesterday) do={
:put ("Yesterday: " . [:pick $yesterday 4 6] . "-" . [:pick $yesterday 0 3] . "-" . [:pick $yesterday 7 10])
:put ("")
:put ("Day before yesterday: " . [:pick $day-before-yesterday 4 6] . "-" . [:pick $day-before-yesterday 0 3] . "-" . [:pick $day-before-yesterday 7 10])
:return
}
}