#20, #24 fixed (Sawako)

This commit is contained in:
JuanjoSalvador
2017-12-02 13:45:46 +01:00
parent e4246a654b
commit 8f1e9947c9
5 changed files with 20 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
# Info about the module # Info about the module
__version__ = '0.5.0' __version__ = '0.6.0'
__author__ = 'Juanjo Salvador' __author__ = 'Juanjo Salvador'
__email__ = 'juanjosalvador@netc.eu' __email__ = 'juanjosalvador@netc.eu'
__url__ = 'http://juanjosalvador.me' __url__ = 'http://juanjosalvador.me'

View File

@@ -3,11 +3,7 @@ from bs4 import BeautifulSoup
from NyaaPy.utils import Utils as utils from NyaaPy.utils import Utils as utils
class Nyaa: class Nyaa:
'''
Return a list of dicts with the results of the query.
'''
def search(keyword, **kwargs): def search(keyword, **kwargs):
category = kwargs.get('category', 0) category = kwargs.get('category', 0)
subcategory = kwargs.get('subcategory', 0) subcategory = kwargs.get('subcategory', 0)
filters = kwargs.get('filters', 0) filters = kwargs.get('filters', 0)
@@ -23,17 +19,19 @@ class Nyaa:
return utils.parse_nyaa(rows, limit=None) return utils.parse_nyaa(rows, limit=None)
def get(id):
def get(url): r = requests.get("http://nyaa.si/view/{}".format(id))
r = requests.get("https://nyaa.si/view/975533")
soup = BeautifulSoup(r.text, 'html.parser') 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) return utils.parse_single(content)
''' def get_user(username):
Returns an array of dicts with the n last updates of Nyaa.si 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): def news(number_of_results):
r = requests.get("http://nyaa.si/") r = requests.get("http://nyaa.si/")
soup = BeautifulSoup(r.text, 'html.parser') soup = BeautifulSoup(r.text, 'html.parser')

View File

@@ -5,7 +5,6 @@ class Pantsu:
# Torrents - GET # Torrents - GET
def search(keyword, **kwargs): 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))) request = requests.get("{}/search{}".format("https://nyaa.pantsu.cat/api", utils.query_builder(keyword, kwargs)))
return request.json() return request.json()

View File

@@ -2,6 +2,8 @@
Module utils Module utils
''' '''
import re
class Utils: class Utils:
def nyaa_categories(b): def nyaa_categories(b):
@@ -69,6 +71,8 @@ class Utils:
return category_name return category_name
def parse_nyaa(table_rows, limit): def parse_nyaa(table_rows, limit):
if limit == 0:
limit = len(table_rows)
torrents = [] torrents = []
@@ -88,6 +92,7 @@ class Utils:
try: try:
torrent = { torrent = {
'id': block[1].replace("/view/", ""),
'category': Utils.nyaa_categories(block[0]), 'category': Utils.nyaa_categories(block[0]),
'url': "http://nyaa.si{}".format(block[1]), 'url': "http://nyaa.si{}".format(block[1]),
'name': block[2], 'name': block[2],
@@ -121,18 +126,18 @@ class Utils:
torrent_files.append(file.text) 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['category'] = data[0]
torrent['uploader'] = data[2] torrent['uploader'] = data[2]
torrent['uploader_profile'] = "https://nyaa.si/user/{}".format(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['size'] = data[6]
torrent['date'] = data[1] torrent['date'] = data[1]
torrent['seeders'] = data[3] torrent['seeders'] = data[3]
torrent['leechers'] = data[5] torrent['leechers'] = data[5]
torrent['completed'] = data[7] torrent['completed'] = data[7]
torrent['hash'] = data[8] 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 torrent['files'] = torrent_files
return torrent return torrent

View File

@@ -1,7 +1,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup(name='nyaapy', setup(name='nyaapy',
version='0.5.0', version='0.6.0',
url='https://github.com/juanjosalvador/nyaapy', url='https://github.com/juanjosalvador/nyaapy',
download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz', download_url = 'https://github.com/juanjosalvador/nyaapy/archive/0.1.tar.gz',
license='MIT', license='MIT',