Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when search result returns nothing. #12

Closed
enderlein opened this issue Jun 18, 2018 · 6 comments
Closed

Errors when search result returns nothing. #12

enderlein opened this issue Jun 18, 2018 · 6 comments
Labels
bug Something isn't working

Comments

@enderlein
Copy link
Contributor

When a search result in anime watch --new returns nothing (i.e. anime watch --new "Kanpai"), it still displays a list of search results, even though it's completely empty.
image

If you select an option, it aborts the search, telling you to input a number less than 31:
image

I think this should be made more graceful. There should either be an option for the user to abort the search on their own or it should tell the user that there are no search results and then abort.

@vn-ki
Copy link
Collaborator

vn-ki commented Jun 18, 2018

Yeah. There are a lot of things to be ironed out in that category.

Funny of me to assume one will get 30 results for every search. If you're willing to open a PR, I'm happy to merge it.

@vn-ki
Copy link
Collaborator

vn-ki commented Jun 18, 2018

If you are okay with it, let @KashTag take up this issue. I'm sure you'll find a lot more bugs!

@enderlein
Copy link
Contributor Author

No problem at all. I'll keep looking.

@vn-ki
Copy link
Collaborator

vn-ki commented Jun 18, 2018

That's great @enderlein.

@KashTag If you are interested, please look into this issue.

EDIT: I'm linking the relevant code below,

https://github.com/vn-ki/anime-downloader/blob/35d6e303d2dca36daa7c359888f959315753b800/anime_downloader/util.py#L40-L62

@vn-ki vn-ki added the bug Something isn't working label Jun 18, 2018
@KashTag
Copy link
Contributor

KashTag commented Jun 19, 2018

Sorry I'm still new to Python so I took my stupid time working this out.
I changed the code like this.

def search(query):
    # Since this function outputs to stdout this should ideally be in
    # cli. But it is used in watch too. :(
    try:
        search_results = NineAnime.search(query)
    except Exception as e:
        logging.error(click.style(str(e), fg='red'))
        sys.exit(1)
    click.echo(format_search_results(search_results))
    if not search_results: 
        print('No such Anime found')
        sys.exit(1)
    val = click.prompt('Enter the anime no: ', type=int, default=1)

    try:
        url = search_results[val-1].url
        title = search_results[val-1].title
    except IndexError:
        logging.error('Only maximum of 30 search results are allowed.'
                      ' Please input a number less than 31')
        sys.exit(1)

    logging.info('Selected {}'.format(title))

    return url

I wish I knew how to make it rerun the function instead of exiting.

Now it shows the following:

capture3

That last edit was a mistake. Sorry i thought the val variable stored the number of search results. I'll try to find it. I closed the accidental pull request.

If I find out then ill use .format and replace 30 and 31

@vn-ki
Copy link
Collaborator

vn-ki commented Jun 19, 2018

#14 closes this.

@vn-ki vn-ki closed this as completed Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants