fixed "self" error (last PR was wrong)

This commit is contained in:
Juanjo Salvador
2019-10-04 20:52:57 +02:00
parent 55950d63a3
commit f1f99a83af
4 changed files with 46 additions and 46 deletions

View File

@@ -1,13 +1,20 @@
import requests import requests
import urllib.parse import urllib.parse
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from NyaaPy.utils import utils from NyaaPy import utils
class Nyaa: class Nyaa:
def __init__(self): def __init__(self):
self.URI = "http://nyaa.si" self.URI = "http://nyaa.si"
def last_uploads(self, number_of_results):
r = requests.get(self.URI)
soup = BeautifulSoup(r.text, 'html.parser')
rows = soup.select('table tr')
return utils.parse_nyaa(table_rows=rows, limit=number_of_results + 1)
def search(self, keyword, **kwargs): def search(self, keyword, **kwargs):
user = kwargs.get('user', None) user = kwargs.get('user', None)
category = kwargs.get('category', 0) category = kwargs.get('category', 0)
@@ -45,10 +52,3 @@ class Nyaa:
soup = BeautifulSoup(r.text, 'html.parser') soup = BeautifulSoup(r.text, 'html.parser')
return utils.parse_nyaa(soup.select('table tr'), limit=None) return utils.parse_nyaa(soup.select('table tr'), limit=None)
def news(self, number_of_results):
r = requests.get(self.URI)
soup = BeautifulSoup(r.text, 'html.parser')
rows = soup.select('table tr')
return utils.parse_nyaa(rows, limit=number_of_results + 1)

View File

@@ -1,5 +1,5 @@
import requests import requests
from NyaaPy.utils import utils from NyaaPy import utils
class Pantsu: class Pantsu:

View File

@@ -1,6 +1,6 @@
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from NyaaPy.utils import utils from NyaaPy import utils
class SukebeiNyaa: class SukebeiNyaa:
def search(self, keyword, **kwargs): def search(self, keyword, **kwargs):

View File

@@ -4,7 +4,7 @@
import re import re
def nyaa_categories(self, b): def nyaa_categories(b):
c = b.replace('/?c=', '') c = b.replace('/?c=', '')
cats = c.split('_') cats = c.split('_')
@@ -69,7 +69,7 @@ def nyaa_categories(self, b):
return category_name return category_name
def parse_nyaa(self, table_rows, limit): def parse_nyaa(table_rows, limit):
if limit == 0: if limit == 0:
limit = len(table_rows) limit = len(table_rows)
@@ -92,7 +92,7 @@ def parse_nyaa(self, table_rows, limit):
try: try:
torrent = { torrent = {
'id': block[1].replace("/view/", ""), 'id': block[1].replace("/view/", ""),
'category': nyaa_categories(self, block[0]), 'category': nyaa_categories(block[0]),
'url': "http://nyaa.si{}".format(block[1]), 'url': "http://nyaa.si{}".format(block[1]),
'name': block[2], 'name': block[2],
'download_url': "http://nyaa.si{}".format(block[4]), 'download_url': "http://nyaa.si{}".format(block[4]),
@@ -110,7 +110,7 @@ def parse_nyaa(self, table_rows, limit):
return torrents return torrents
def parse_single(self, content): def parse_single(content):
torrent = {} torrent = {}
data = [] data = []
torrent_files = [] torrent_files = []
@@ -143,45 +143,45 @@ def parse_single(self, content):
return torrent return torrent
def parse_sukebei(self, table_rows, limit): # def parse_sukebei(table_rows, limit):
if limit == 0: # if limit == 0:
limit = len(table_rows) # limit = len(table_rows)
torrents = [] # torrents = []
for row in table_rows[:limit]: # for row in table_rows[:limit]:
block = [] # block = []
for td in row.find_all('td'): # for td in row.find_all('td'):
for link in td.find_all('a'): # for link in td.find_all('a'):
if link.get('href')[-9:] != '#comments': # if link.get('href')[-9:] != '#comments':
block.append(link.get('href')) # block.append(link.get('href'))
block.append(link.text.rstrip()) # block.append(link.text.rstrip())
if td.text.rstrip(): # if td.text.rstrip():
block.append(td.text.rstrip()) # block.append(td.text.rstrip())
try: # try:
torrent = { # torrent = {
'id': block[1].replace("/view/", ""), # 'id': block[1].replace("/view/", ""),
'category': sukebei_categories(self, block[0]), # 'category': sukebei_categories(block[0]),
'url': "http://sukebei.nyaa.si{}".format(block[1]), # 'url': "http://sukebei.nyaa.si{}".format(block[1]),
'name': block[2], # 'name': block[2],
'download_url': "http://sukebei.nyaa.si{}".format( # 'download_url': "http://sukebei.nyaa.si{}".format(
block[4]), # block[4]),
'magnet': block[5], # 'magnet': block[5],
'size': block[6], # 'size': block[6],
'date': block[7], # 'date': block[7],
'seeders': block[8], # 'seeders': block[8],
'leechers': block[9], # 'leechers': block[9],
'completed_downloads': block[10], # 'completed_downloads': block[10],
} # }
torrents.append(torrent) # torrents.append(torrent)
return torrents # return torrents
def sukebei_categories(self, b): def sukebei_categories(b):
c = b.replace('/?c=', '') c = b.replace('/?c=', '')
cats = c.split('_') cats = c.split('_')
@@ -217,7 +217,7 @@ def sukebei_categories(self, b):
return category_name return category_name
# Pantsu Utils # Pantsu Utils
def query_builder(self, q, params): def query_builder(q, params):
available_params = ["category", "page", "limit", "userID", "fromID", available_params = ["category", "page", "limit", "userID", "fromID",
"status", "maxage", "toDate", "fromDate", "status", "maxage", "toDate", "fromDate",
"dateType", "minSize", "maxSize", "sizeType", "dateType", "minSize", "maxSize", "sizeType",