mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
feat(completions): enhance speed of loading completion functions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import click
|
||||
|
||||
from ...utils.completion_types import anime_titles_shell_complete
|
||||
from ...completion_functions import anime_titles_shell_complete
|
||||
|
||||
|
||||
@click.command(
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
import click
|
||||
|
||||
from ..utils.completion_types import anime_titles_shell_complete
|
||||
from ..completion_functions import anime_titles_shell_complete
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..config import Config
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import click
|
||||
|
||||
from ...cli.config import Config
|
||||
from ..utils.completion_types import anime_titles_shell_complete
|
||||
from ..completion_functions import anime_titles_shell_complete
|
||||
|
||||
|
||||
@click.command(
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import requests
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ...libs.anilist.types import AnilistDataSchema
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -43,13 +36,15 @@ def get_anime_titles(query: str, variables: dict = {}):
|
||||
Returns:
|
||||
a boolean indicating success and none or an anilist object depending on success
|
||||
"""
|
||||
from requests import post
|
||||
|
||||
try:
|
||||
response = requests.post(
|
||||
response = post(
|
||||
ANILIST_ENDPOINT,
|
||||
json={"query": query, "variables": variables},
|
||||
timeout=10,
|
||||
)
|
||||
anilist_data: AnilistDataSchema = response.json()
|
||||
anilist_data = response.json()
|
||||
|
||||
# ensuring you dont get blocked
|
||||
if (
|
||||
@@ -78,20 +73,10 @@ def get_anime_titles(query: str, variables: dict = {}):
|
||||
]
|
||||
return [*eng_titles, *romaji_titles]
|
||||
else:
|
||||
return ["non 200 status code"]
|
||||
except requests.exceptions.Timeout:
|
||||
logger.warning(
|
||||
"Timeout has been exceeded this could mean anilist is down or you have lost internet connection"
|
||||
)
|
||||
return ["timeout exceeded"]
|
||||
except requests.exceptions.ConnectionError:
|
||||
logger.warning(
|
||||
"ConnectionError this could mean anilist is down or you have lost internet connection"
|
||||
)
|
||||
return ["connection error"]
|
||||
return []
|
||||
except Exception as e:
|
||||
logger.error(f"Something unexpected occured {e}")
|
||||
return ["unexpected error"]
|
||||
return []
|
||||
|
||||
|
||||
def anime_titles_shell_complete(ctx, param, incomplete):
|
||||
Reference in New Issue
Block a user