From a8bd8a093233d5e1c7f5a4956a1afe49facef996 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 24 May 2024 22:02:38 +0200 Subject: [PATCH] Only fetch translations if an internet connection is active --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 234fe41..f3fd58b 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -import os, asyncio, sys, time, aiohttp, json +import os, asyncio, sys, time, aiohttp, json, socket from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer @@ -32,6 +32,13 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): if SUCCESSFUL_FETCH_THIS_RUN: return + + try: + socket.setdefaulttimeout(3) + socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect(("8.8.8.8", 53)) + except: + Log("No internet connection. Not fetching css translations") + return setting = util_store_read("beta_translations") @@ -43,7 +50,7 @@ async def fetch_class_mappings(css_translations_path : str, loader : Loader): Log(f"Fetching CSS mappings from {css_translations_url}") try: - async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) as session: + async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl=False, use_dns_cache=False), timeout=aiohttp.ClientTimeout(total=5)) as session: async with session.get(css_translations_url) as response: if response.status == 200: text = await response.text()