From daaedaff94559eb36d4e83de1fa6f157a0c81b6e Mon Sep 17 00:00:00 2001 From: Anes Belfodil Date: Mon, 9 Dec 2024 00:07:52 -0500 Subject: [PATCH] Update dependencies --- config.py | 2 +- connection.py | 4 ++-- requirements.txt | 7 +++---- wallpaper.py | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/config.py b/config.py index 224ef96..29dbb6c 100644 --- a/config.py +++ b/config.py @@ -1,6 +1,6 @@ from watchfiles import watch from threading import Thread -from appdirs import user_config_dir +from platformdirs import user_config_dir import json from os import path, makedirs from log import get_logger diff --git a/connection.py b/connection.py index e89932d..61a2d02 100644 --- a/connection.py +++ b/connection.py @@ -1,10 +1,10 @@ -from requests import get +from urllib.request import urlopen, Request from time import sleep def _is_connected(): try: - get("https://1.1.1.1") + urlopen(Request("https://1.1.1.1", headers={"User-Agent": "randwall/1.0"})) return True except: return False diff --git a/requirements.txt b/requirements.txt index 09c414d..f81c70d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ -pyinstaller==5.7.0 -appdirs==1.4.4 -watchfiles==0.18.1 -requests==2.28.1 +platformdirs==4.3.6 +pyinstaller==6.11.1 +watchfiles==1.0.0 diff --git a/wallpaper.py b/wallpaper.py index 13406b4..f9d91dd 100644 --- a/wallpaper.py +++ b/wallpaper.py @@ -1,7 +1,9 @@ +import json import platform import os from log import get_logger -from requests import get +from urllib.request import urlopen, Request +from urllib.parse import urlencode from config import config import subprocess import tempfile @@ -72,9 +74,9 @@ def _dict_to_binary_string(dm, order): def _get_random_wallpaper(): - api_url = "https://wallhaven.cc/api/v1/search" + api_url = "https://wallhaven.cc/api/v1/search?" params = { - "apikey": {config['api_key']}, + "apikey": config['api_key'], "categories": _dict_to_binary_string(config['categories'], ['general', 'anime', 'people']), "purity": _dict_to_binary_string(config['purity'], ['sfw', 'sketchy', 'nsfw']), "q": config['tags'], @@ -83,13 +85,11 @@ def _get_random_wallpaper(): "page": "1", "ratios": "16x9,16x10", } - headers = { - "User-Agent": "randwall/1.0" - } try: - response = get(api_url, params=params, headers=headers) - data = response.json() + with urlopen(Request(api_url + urlencode(params), headers={"User-Agent": "randwall/1.0"})) as f: + response = f.read().decode("utf-8") + data = json.loads(response) image_data = data["data"][0] return { "id": image_data["id"], @@ -108,7 +108,8 @@ def _download_wallpaper(wallpaper): logger.info(f"Downloading {wallpaper['url']} at {image_path}") try: - image = get(wallpaper['path']).content + with urlopen(Request(wallpaper["path"], headers={"User-Agent": "randwall/1.0"})) as f: + image = f.read() except: return