Files
KomSuite-NyaaPy/NyaaPy/nyaa.py
2018-03-08 23:33:54 +01:00

46 lines
1.5 KiB
Python

import requests
from bs4 import BeautifulSoup
from NyaaPy.utils import Utils
utils = Utils()
class Nyaa:
def __init__(self):
self.URI = "http://nyaa.si"
def search(self, 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("{}/?f={}&c={}_{}&q={}&p={}".format(self.URI, filters, category, subcategory, keyword, page))
else:
r = requests.get("{}/?f={}&c={}_{}&q={}".format(self.URI, filters, category, subcategory, keyword))
soup = BeautifulSoup(r.text, 'html.parser')
rows = soup.select('table tr')
return utils.parse_nyaa(rows, limit=None)
def get(self, id):
r = requests.get("{}/view/{}".format(self.URI, id))
soup = BeautifulSoup(r.text, 'html.parser')
content = soup.findAll("div", { "class": "panel", "id": None})
return utils.parse_single(content)
def get_user(self, username):
r = requests.get("{}/user/{}".format(self.URI, username))
soup = BeautifulSoup(r.text, 'html.parser')
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)