refactor(Mainsail): use urllib.request instead of requests module

requests is actually not part of the python 3.8 standard library, hence we use urllib.request now, which is.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-02-18 22:08:21 +01:00
parent 05b4ef2d18
commit 573dc7c3c9
2 changed files with 16 additions and 6 deletions

View File

@@ -11,10 +11,11 @@
import json
import shutil
from json import JSONDecodeError
from pathlib import Path
from typing import List
import requests
import urllib.request
from kiauh.components.klipper.klipper import Klipper
from kiauh.components.mainsail import (
@@ -99,9 +100,12 @@ def get_mainsail_local_version() -> str:
def get_mainsail_remote_version() -> str:
url = "https://api.github.com/repos/mainsail-crew/mainsail/tags"
response = requests.get(url)
data = json.loads(response.text)
return data[0]["name"]
try:
with urllib.request.urlopen(url) as response:
data = json.loads(response.read())
return data[0]["name"]
except (JSONDecodeError, TypeError):
return "ERROR"
def backup_mainsail_data() -> None:

View File

@@ -24,7 +24,13 @@ from kiauh.components.moonraker.moonraker_setup import update_moonraker
from kiauh.components.moonraker.moonraker_utils import get_moonraker_status
from kiauh.core.menus import BACK_FOOTER
from kiauh.core.menus.base_menu import BaseMenu
from kiauh.utils.constants import COLOR_GREEN, RESET_FORMAT, COLOR_YELLOW, COLOR_WHITE
from kiauh.utils.constants import (
COLOR_GREEN,
RESET_FORMAT,
COLOR_YELLOW,
COLOR_WHITE,
COLOR_RED,
)
# noinspection PyUnusedLocal
@@ -159,4 +165,4 @@ class UpdateMenu(BaseMenu):
self.ms_local = f"{COLOR_GREEN}{self.ms_local}{RESET_FORMAT}"
else:
self.ms_local = f"{COLOR_YELLOW}{self.ms_local}{RESET_FORMAT}"
self.ms_remote = f"{COLOR_GREEN}{self.ms_remote}{RESET_FORMAT}"
self.ms_remote = f"{COLOR_GREEN if self.ms_remote != 'ERROR' else COLOR_RED}{self.ms_remote}{RESET_FORMAT}"