From 604833461c6447c6720490f3b7836bca3dfef6c5 Mon Sep 17 00:00:00 2001 From: stef-devs Date: Fri, 24 Jun 2022 14:25:21 +0200 Subject: [PATCH] Fix uptime command --- index.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/index.py b/index.py index 727176a..f0ae15b 100644 --- a/index.py +++ b/index.py @@ -14,8 +14,6 @@ import python_weather import asyncio import json import goslate -import urllib.request -import urllib.parse import logging import deepl import spotipy @@ -339,13 +337,19 @@ def uptime(message): def uptime_step(message): text = message.text - url= text - status_code = urllib.request.urlopen(url).getcode() - website_is_up = status_code == 200 - if website_is_up == True: - bot.send_message(message.chat.id, "Il sito è online!") - else: - bot.send_message(message.chat.id, "Il sito non è online!") + try: + x = requests.get(text) + if x.status_code == 200: + bot.send_message(message.chat.id, "Il sito è online, puoi festeggiare adesso! :tada:") + except requests.exceptions.ConnectionError: + bot.send_message(message.chat.id, "Il sito non esiste oppure è offline, sad...") + # status_code = urllib.request.urlopen(url).getcode() + # website_is_up = status_code == 200 + # try + # if website_is_up == True: + # bot.send_message(message.chat.id, "Il sito è online!") + # except: + # bot.send_message(message.chat.id, "Si è verificato un errore") #Command /convert @bot.message_handler(commands=["convert"])