From e4246a654bd5fcce4b3ec1ad1b284e610054d540 Mon Sep 17 00:00:00 2001 From: JuanjoSalvador Date: Sat, 4 Nov 2017 01:07:26 +0100 Subject: [PATCH] #19 fixed, need to be tested --- NyaaPy/nyaa.py | 13 ++++++++----- NyaaPy/utils.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index d9b7591..0814ee0 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -21,13 +21,16 @@ class Nyaa: soup = BeautifulSoup(r.text, 'html.parser') rows = soup.select('table tr') - results = {} + return utils.parse_nyaa(rows, limit=None) - if rows: - results = utils.parse_nyaa(rows, limit=None) - return results - + def get(url): + r = requests.get("https://nyaa.si/view/975533") + soup = BeautifulSoup(r.text, 'html.parser') + content = soup.findAll("div", { "class": "panel panel-default", "id": None}) + + return utils.parse_single(content) + ''' Returns an array of dicts with the n last updates of Nyaa.si ''' diff --git a/NyaaPy/utils.py b/NyaaPy/utils.py index 2a18cf8..f1d50be 100644 --- a/NyaaPy/utils.py +++ b/NyaaPy/utils.py @@ -2,7 +2,7 @@ Module utils ''' -class Utils(): +class Utils: def nyaa_categories(b): c = b.replace('/?c=', '') @@ -106,6 +106,37 @@ class Utils(): return torrents + def parse_single(content): + torrent = {} + data = [] + torrent_files = [] + + for row in content[0].find_all('div', {'class': 'row'}): + for div in row.find_all('div', {'class': 'col-md-5'}): + data.append(div.text.replace("\n", "")) + + files = content[2].find('div', {'class', 'torrent-file-list'}).find_all('li') + + for file in files: + torrent_files.append(file.text) + + + torrent['title'] = 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['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['files'] = torrent_files + + return torrent + def query_builder(q, params): available_params = ["category", "page", "limit", "userID", "fromID", "status", "maxage", "toDate", "fromDate",\ "dateType", "minSize", "maxSize", "sizeType", "sort", "order", "lang"]