Answer the question
In order to leave comments, you need to log in
How to correctly set Class and conditions for ping?
I welcome everyone!
Tell me how, if the "else" condition is met, send a message to the user once, and not spam? And in case of reappearance of ping - send the message "Connection restored" to the user and return back to the beginning of the cycle.
Thanks in advance!
hostname = "*****"
channel = '*****'
bot = telebot.TeleBot(<TOKEN>)
class RepeatTimer(Timer):
def run(self):
while not self.finished.wait(self.interval):
self.function(*self.args, **self.kwargs)
def select():
response = os.system('ping ' + hostname)
if response == 0:
print(hostname + ' пингуется')
bot.send_message(channel , hostname + ' интернет есть')
else:
print(hostname + ' не пингуется')
bot.send_message(channel , hostname + ' интернета нет')
if __name__=='__main__':
RepeatTimer(30, select).start()
bot.polling(none_stop=True)
type object 'stat' has no attribute 'status'
class stat():
def contrl_stat(self):
self.status = True
def check_ip_two():
hostname = Config.ip
if check_ip():
if not stat.status:
stat.status = True
bot.send_message(channel, hostname + ' интернет есть')
else:
if (stat.status):
stat.status = False
bot.send_message(channel, hostname + ' интернет есть')
def check_ip():
hostname = Config.ip
response = os.system('ping ' + hostname)
if response == 0:
return True
else:
return False
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question