From 600cba9e7cd9bf4f06da26535222e822ec2d5beb Mon Sep 17 00:00:00 2001 From: Insomnia731 <120348762+Insomnia731@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:37:10 +0300 Subject: [PATCH] Update start_main.py --- start_main.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/start_main.py b/start_main.py index 1a31cb6..7678a11 100644 --- a/start_main.py +++ b/start_main.py @@ -9,14 +9,19 @@ async def get_ip_info(): try: async with aiohttp.ClientSession() as session: async with session.get("https://ipinfo.io") as response: - data = await response.json() - - ip = data.get('ip') - city = data.get('city') - country = data.get('country') - - print(f"IP: {ip}") - print(f"Location: {city}, {country}") + if response.status == 200: + data = await response.json() + + ip = data.get('ip') + city = data.get('city') + country = data.get('country') + + print(f"IP: {ip}") + print(f"Location: {city}, {country}") + else: + # Получаем текст ошибки, если не 200 + error_text = await response.text() + print(f"Error: {response.status}, {error_text}") except Exception as e: print(f"Error: {e}") @@ -28,5 +33,5 @@ def run_main(arg=None): if __name__ == "__main__": asyncio.run(get_ip_info()) - time.sleep(random.randint(0, 60*2)) # 2 минуты + time.sleep(random.randint(0, 5)) # 2 минуты run_main(["-a", "2"]) # Запускает main.py -a 2