Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
abelfodil committed Dec 9, 2024
1 parent c5c5f23 commit daaedaf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions connection.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 3 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
19 changes: 10 additions & 9 deletions wallpaper.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'],
Expand All @@ -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"],
Expand All @@ -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

Expand Down

0 comments on commit daaedaf

Please sign in to comment.