From 8f1e9947c9d12ac8c75e71abe073aaa2abdea003 Mon Sep 17 00:00:00 2001 From: JuanjoSalvador Date: Sat, 2 Dec 2017 13:45:46 +0100 Subject: [PATCH] #20, #24 fixed (Sawako) --- NyaaPy/__init__.py | 2 +- NyaaPy/nyaa.py | 22 ++++++++++------------ NyaaPy/pantsu.py | 1 - NyaaPy/utils.py | 11 ++++++++--- setup.py | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/NyaaPy/__init__.py b/NyaaPy/__init__.py index 03f690a..5ca75df 100644 --- a/NyaaPy/__init__.py +++ b/NyaaPy/__init__.py @@ -1,5 +1,5 @@ # Info about the module -__version__ = '0.5.0' +__version__ = '0.6.0' __author__ = 'Juanjo Salvador' __email__ = 'juanjosalvador@netc.eu' __url__ = 'http://juanjosalvador.me' diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index 0814ee0..ec8cbf9 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -3,11 +3,7 @@ from bs4 import BeautifulSoup from NyaaPy.utils import Utils as utils class Nyaa: - ''' - Return a list of dicts with the results of the query. - ''' def search(keyword, **kwargs): - category = kwargs.get('category', 0) subcategory = kwargs.get('subcategory', 0) filters = kwargs.get('filters', 0) @@ -23,17 +19,19 @@ class Nyaa: return utils.parse_nyaa(rows, limit=None) - - def get(url): - r = requests.get("https://nyaa.si/view/975533") + def get(id): + r = requests.get("http://nyaa.si/view/{}".format(id)) soup = BeautifulSoup(r.text, 'html.parser') - content = soup.findAll("div", { "class": "panel panel-default", "id": None}) - + content = soup.findAll("div", { "class": "panel", "id": None}) + return utils.parse_single(content) - ''' - Returns an array of dicts with the n last updates of Nyaa.si - ''' + def get_user(username): + r = requests.get("http://nyaa.si/user/{}".format(username)) + soup = BeautifulSoup(r.text, 'html.parser') + + return utils.parse_nyaa(soup.select('table tr'), limit=None) + def news(number_of_results): r = requests.get("http://nyaa.si/") soup = BeautifulSoup(r.text, 'html.parser') diff --git a/NyaaPy/pantsu.py b/NyaaPy/pantsu.py index e508077..b25a99e 100644 --- a/NyaaPy/pantsu.py +++ b/NyaaPy/pantsu.py @@ -5,7 +5,6 @@ class Pantsu: # Torrents - GET def search(keyword, **kwargs): - print(utils.query_builder(keyword, kwargs)) request = requests.get("{}/search{}".format("https://nyaa.pantsu.cat/api", utils.query_builder(keyword, kwargs))) return request.json() diff --git a/NyaaPy/utils.py b/NyaaPy/utils.py index f1d50be..91b9bcb 100644 --- a/NyaaPy/utils.py +++ b/NyaaPy/utils.py @@ -2,6 +2,8 @@ Module utils ''' +import re + class Utils: def nyaa_categories(b): @@ -69,6 +71,8 @@ class Utils: return category_name def parse_nyaa(table_rows, limit): + if limit == 0: + limit = len(table_rows) torrents = [] @@ -88,6 +92,7 @@ class Utils: try: torrent = { + 'id': block[1].replace("/view/", ""), 'category': Utils.nyaa_categories(block[0]), 'url': "http://nyaa.si{}".format(block[1]), 'name': block[2], @@ -121,18 +126,18 @@ class Utils: torrent_files.append(file.text) - torrent['title'] = content[0].find('h3', {"class": "panel-title"}).text.replace("\n", "") + torrent['title'] = re.sub('\n|\r|\t', '', content[0].find('h3', {"class": "panel-title"}).text.replace("\n", "")) torrent['category'] = data[0] torrent['uploader'] = data[2] torrent['uploader_profile'] = "https://nyaa.si/user/{}".format(data[2]) - torrent['website'] = data[4] + torrent['website'] = re.sub('\t', '', data[4]) torrent['size'] = data[6] torrent['date'] = data[1] torrent['seeders'] = data[3] torrent['leechers'] = data[5] torrent['completed'] = data[7] torrent['hash'] = data[8] - torrent['description'] = content[1].find('div', {'id': 'torrent-description'}).text + torrent['description'] = re.sub('\t', '', content[1].find('div', {'id': 'torrent-description'}).text) torrent['files'] = torrent_files return torrent diff --git a/setup.py b/setup.py index 7475a97..ff870e4 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='nyaapy', - version='0.5.0', + version='0.6.0', url='https://github.com/juanjosalvador/nyaapy', download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz', license='MIT',