From 7c8b6142936c9a7291df0771f336d70ebec44078 Mon Sep 17 00:00:00 2001 From: JuanjoSalvador Date: Wed, 1 Nov 2017 00:38:22 +0100 Subject: [PATCH] Fix #14 --- NyaaPy/nyaa.py | 10 ++++++++-- README.md | 10 +++++----- setup.py | 2 +- tests/test.py | 35 ++++++++--------------------------- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index c7eab47..daebb61 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -6,7 +6,13 @@ class Nyaa(): ''' Return a list of dicts with the results of the query. ''' - def search(keyword, category, subcategory, filters, page): + def search(keyword, **kwargs): + + category = kwargs.get('category', 0) + subcategory = kwargs.get('subcategory', 0) + filters = kwargs.get('filters', 0) + page = kwargs.get('page', 0) + if page > 0: r = requests.get("http://nyaa.si/?f={}&c={}_{}&q={}&p={}".format(filters, category, subcategory, keyword, page)) else: @@ -30,4 +36,4 @@ class Nyaa(): soup = BeautifulSoup(r.text, 'html.parser') rows = soup.select('table tr') - return utils.parse_nyaa(rows, limit=number_of_results) \ No newline at end of file + return utils.parse_nyaa(rows, limit=number_of_results + 1) \ No newline at end of file diff --git a/README.md b/README.md index 6c86de0..f826e5f 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,11 @@ Returns a list of dicts with the search results. Parameters: -* **keyword**: String. Keyword for the search query. -* **category**: Integer. -* **subcategory**: Integer. -* **filters**: Integer. -* **page**: Integer. +* **keyword**: String. Keyword for the search query. Mandatory. +* **category**: Integer. Optional. +* **subcategory**: Integer. Optional. +* **filters**: Integer. Optional. +* **page**: Integer. Optional. `page` must be between 0 and 1000. diff --git a/setup.py b/setup.py index 8a36b5b..6028d87 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='nyaapy', - version='0.4.1', + version='0.4.3', url='https://github.com/juanjosalvador/nyaapy', download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz', license='MIT', diff --git a/tests/test.py b/tests/test.py index fb8671c..efca379 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,31 +1,12 @@ -from NyaaPy import Nyaa, NyaaPantsu +from NyaaPy import Nyaa # Nyaa.si results -def nyaa_search(): - try: - nyaa_query = Nyaa.search(keyword='koe no katachi 1080', category=1, subcategory=0, page=0) +nyaa_query = Nyaa.search() - for nyaa in nyaa_query: - print(nyaa) - except TypeError as te: - print(te) +nyaa_news = Nyaa.news(5) -def nyaa_news(): - news = Nyaa.news(number_of_results=5) - for n in news: - print(n) - -# Nyaa.pantsu.cat results -def pantsu_search(): - pantsu_query = NyaaPantsu.search('new game!!') - - -def pantsu_news(): - print(NyaaPantsu.news(1)) - -# Uncomment whatever you want to test - -#nyaa_search() -#pantsu_search() -#nyaa_news() -pantsu_news() \ No newline at end of file +if len(nyaa_query) > 0: + for result in nyaa_query: + print(result['name']) +else: + print('Nothing here!') \ No newline at end of file