feat(cli):improve anilist interfaces api

This commit is contained in:
Benex254
2024-06-29 22:00:48 +03:00
parent 7d82a356b1
commit 520bfcbb52
16 changed files with 503 additions and 246 deletions

View File

@@ -0,0 +1,24 @@
import shutil
import subprocess
import requests
def print_img(url: str):
executable = shutil.which("chafa")
curl = shutil.which("curl")
# curl -sL "$1" | chafa /dev/stdin
if executable is None or curl is None:
print("chafa or curl not found")
return
res = requests.get(url)
if res.status_code != 200:
print("Error fetching image")
return
img_bytes = res.content
if not img_bytes:
print("No image found")
img_bytes = subprocess.check_output([curl, "-sL", url])
subprocess.run([executable, url, "--size=15x15"], input=img_bytes)

View File

@@ -0,0 +1,13 @@
class QueryDict(dict):
"""dot.notation access to dictionary attributes"""
def __getattr__(self, attr):
try:
return self.__getitem__(attr)
except KeyError:
raise AttributeError(
"%r object has no attribute %r" % (self.__class__.__name__, attr)
)
def __setattr__(self, attr, value):
self.__setitem__(attr, value)

View File

@@ -20,7 +20,12 @@ def clear():
def fuzzy_inquirer(prompt: str, choices, **kwargs):
clear()
action = inquirer.fuzzy(
prompt, choices, height="100%", border=True, **kwargs
prompt,
choices,
height="100%",
border=True,
validate=lambda result: result in choices,
**kwargs,
).execute()
return action