Skip to content

Commit

Permalink
feat(cli):complete subcommands for anilist command
Browse files Browse the repository at this point in the history
  • Loading branch information
Benex254 committed Jun 30, 2024
1 parent 520bfcb commit 2aa02d6
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
3 changes: 3 additions & 0 deletions fastanime/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sys import exit

import click

from .. import __version__
Expand All @@ -14,6 +16,7 @@
"download": download,
"anilist": anilist,
"config": configure,
"exit": exit,
}


Expand Down
5 changes: 5 additions & 0 deletions fastanime/cli/commands/anilist/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from sys import exit

import click

from ...interfaces.anilist_interfaces import anilist as anilist_interface
from ...utils.tools import QueryDict
from .favourites import favourites
from .popular import popular
from .recent import recent
from .scores import scores
from .search import search
from .trending import trending
from .upcoming import upcoming
Expand All @@ -15,7 +18,9 @@
"search": search,
"popular": popular,
"trending": trending,
"scores": scores,
"upcoming": upcoming,
"exit": exit,
}


Expand Down
13 changes: 11 additions & 2 deletions fastanime/cli/commands/anilist/popular.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import click

from ....libs.anilist.anilist import AniList
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
def popular():
print("popular")
@click.pass_obj
def popular(config):
anime_data = AniList.get_most_popular()
if anime_data[0]:
anilist_config = QueryDict()
anilist_config.data = anime_data[1]
select_anime(config, anilist_config)
13 changes: 11 additions & 2 deletions fastanime/cli/commands/anilist/recent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import click

from ....libs.anilist.anilist import AniList
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
def recent():
print("recent")
@click.pass_obj
def recent(config):
anime_data = AniList.get_most_recently_updated()
if anime_data[0]:
anilist_config = QueryDict()
anilist_config.data = anime_data[1]
select_anime(config, anilist_config)
15 changes: 15 additions & 0 deletions fastanime/cli/commands/anilist/scores.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import click

from ....libs.anilist.anilist import AniList
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
@click.pass_obj
def scores(config):
anime_data = AniList.get_most_scored()
if anime_data[0]:
anilist_config = QueryDict()
anilist_config.data = anime_data[1]
select_anime(config, anilist_config)
12 changes: 8 additions & 4 deletions fastanime/cli/commands/anilist/search.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import click

from ....libs.anilist.anilist import AniList
from .utils import get_search_result
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
@click.option("--title", prompt="Enter anime title")
def search(title):
@click.pass_obj
def search(config, title):
success, search_results = AniList.search(title)
if search_results and success:
get_search_result(search_results)
if success:
anilist_config = QueryDict()
anilist_config.data = search_results
select_anime(config, anilist_config)
14 changes: 9 additions & 5 deletions fastanime/cli/commands/anilist/trending.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import click

from ....libs.anilist.anilist import AniList
from .utils import get_search_result
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
def trending():
success, trending = AniList.get_trending()
if trending and success:
get_search_result(trending)
@click.pass_obj
def trending(config):
success, data = AniList.get_trending()
if success:
anilist_config = QueryDict()
anilist_config.data = data
select_anime(config, anilist_config)
13 changes: 11 additions & 2 deletions fastanime/cli/commands/anilist/upcoming.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import click

from ....libs.anilist.anilist import AniList
from ...interfaces.anilist_interfaces import select_anime
from ...utils.tools import QueryDict


@click.command()
def upcoming():
print("upcoming")
@click.pass_obj
def upcoming(config):
success, data = AniList.get_upcoming_anime()
if success:
anilist_config = QueryDict()
anilist_config.data = data
select_anime(config, anilist_config)
11 changes: 6 additions & 5 deletions fastanime/cli/interfaces/anilist_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from ..utils.utils import clear, fuzzy_inquirer


# FIXME: BACK brocken
def player_controls(config: Config, anilist_config: QueryDict):
# user config
translation_type: str = config.translation_type
Expand Down Expand Up @@ -112,14 +111,14 @@ def _change_translation_type():
options = {
"Replay": _replay,
"Next Episode": _next_episode,
"Episodes": _episodes,
"Previous Episode": _previous_episode,
"Episodes": _episodes,
"Change Quality": _change_quality,
"Change Translation Type": _change_translation_type,
"Back to servers": _back,
"Go to Main Menu": lambda: anilist(config, anilist_config),
"Go to Anime Options Menu": lambda: anilist_options(config, anilist_config),
"Go to Search Results": lambda: select_anime(config, anilist_config),
"Main Menu": lambda: anilist(config, anilist_config),
"Anime Options Menu": lambda: anilist_options(config, anilist_config),
"Search Results": lambda: select_anime(config, anilist_config),
"exit": sys.exit,
}

Expand Down Expand Up @@ -350,6 +349,7 @@ def _view_info(config, anilist_config):
"view info": _view_info,
"Change Translation Type": _change_translation_type,
"back": select_anime,
"exit": sys.exit,
}
action = fuzzy_inquirer("Select Action:", options.keys())
options[action](config, anilist_config)
Expand Down Expand Up @@ -396,6 +396,7 @@ def _anilist_search():
"most scored anime": AniList.get_most_scored,
"upcoming anime": AniList.get_upcoming_anime,
"recently updated anime": AniList.get_most_recently_updated,
"exit": sys.exit,
}
action = fuzzy_inquirer("Select Action:", options.keys())
anilist_data = options[action]()
Expand Down

0 comments on commit 2aa02d6

Please sign in to comment.