Integrated Pantsu on NyaaPy again!
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
# Info about the module
|
||||
__version__ = '0.4.1'
|
||||
__version__ = '0.5.0'
|
||||
__author__ = 'Juanjo Salvador'
|
||||
__email__ = 'juanjosalvador@netc.eu'
|
||||
__url__ = 'http://juanjosalvador.me'
|
||||
__copyright__ = '2017 Juanjo Salvador'
|
||||
__license__ = 'MIT license'
|
||||
|
||||
from NyaaPy.nyaa import Nyaa
|
||||
from NyaaPy.nyaa import Nyaa
|
||||
from NyaaPy.pantsu import Pantsu
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from NyaaPy.utils import Utils as utils
|
||||
|
||||
class Nyaa():
|
||||
class Nyaa:
|
||||
'''
|
||||
Return a list of dicts with the results of the query.
|
||||
'''
|
||||
@@ -14,9 +14,9 @@ class Nyaa():
|
||||
page = kwargs.get('page', 0)
|
||||
|
||||
if page > 0:
|
||||
r = requests.get("http://nyaa.si/?f={}&c={}_{}&q={}&p={}".format(filters, category, subcategory, keyword, page))
|
||||
r = requests.get("{}/?f={}&c={}_{}&q={}&p={}".format("http://nyaa.si", filters, category, subcategory, keyword, page))
|
||||
else:
|
||||
r = requests.get("http://nyaa.si/?f={}&c={}_{}&q={}".format(filters, category, subcategory, keyword))
|
||||
r = requests.get("{}/?f={}&c={}_{}&q={}".format("http://nyaa.si", filters, category, subcategory, keyword))
|
||||
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
rows = soup.select('table tr')
|
||||
|
||||
30
NyaaPy/pantsu.py
Normal file
30
NyaaPy/pantsu.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import requests
|
||||
from NyaaPy.utils import Utils as utils
|
||||
|
||||
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()
|
||||
|
||||
def view(item_id):
|
||||
request = requests.get("/view/{}".format("https://nyaa.pantsu.cat/api", item_id))
|
||||
|
||||
return request.json()
|
||||
|
||||
# Torrents - POST
|
||||
|
||||
# Users
|
||||
|
||||
def login(username, password):
|
||||
login = requests.post("{}/login/".format(BASE_URL), data={'username': username, 'password': password})
|
||||
|
||||
return login.json()
|
||||
|
||||
def profile(user_id):
|
||||
profile = requests.post("{}/profile/".format(BASE_URL), data={'id': user_id})
|
||||
|
||||
return profile.json()
|
||||
@@ -104,4 +104,26 @@ class Utils():
|
||||
except IndexError as ie:
|
||||
pass
|
||||
|
||||
return torrents
|
||||
return torrents
|
||||
|
||||
def query_builder(q, params):
|
||||
available_params = ["category", "page", "limit", "userID", "fromID", "status", "maxage", "toDate", "fromDate",\
|
||||
"dateType", "minSize", "maxSize", "sizeType", "sort", "order", "lang"]
|
||||
query = "?q={}".format(q.replace(" ", "+"))
|
||||
|
||||
for param, value in params.items():
|
||||
if param in available_params:
|
||||
if param != "category" and param != "status" and param != "lang":
|
||||
query += "&{}={}".format(param, value)
|
||||
else:
|
||||
if param == "category":
|
||||
query += "&c={}_{}".format(value[0], value[1])
|
||||
|
||||
if param == "status":
|
||||
query += "&s={}".format(value)
|
||||
|
||||
if param == "lang":
|
||||
for lang in value:
|
||||
query += "&lang={}".format(lang)
|
||||
|
||||
return query
|
||||
Reference in New Issue
Block a user