Integrated Pantsu on NyaaPy again!
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Info about the module
|
# Info about the module
|
||||||
__version__ = '0.4.1'
|
__version__ = '0.5.0'
|
||||||
__author__ = 'Juanjo Salvador'
|
__author__ = 'Juanjo Salvador'
|
||||||
__email__ = 'juanjosalvador@netc.eu'
|
__email__ = 'juanjosalvador@netc.eu'
|
||||||
__url__ = 'http://juanjosalvador.me'
|
__url__ = 'http://juanjosalvador.me'
|
||||||
@@ -7,3 +7,4 @@ __copyright__ = '2017 Juanjo Salvador'
|
|||||||
__license__ = 'MIT license'
|
__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 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.
|
Return a list of dicts with the results of the query.
|
||||||
'''
|
'''
|
||||||
@@ -14,9 +14,9 @@ class Nyaa():
|
|||||||
page = kwargs.get('page', 0)
|
page = kwargs.get('page', 0)
|
||||||
|
|
||||||
if 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:
|
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')
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
rows = soup.select('table tr')
|
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()
|
||||||
@@ -105,3 +105,25 @@ class Utils():
|
|||||||
pass
|
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
|
||||||
14
README.md
14
README.md
@@ -4,27 +4,23 @@
|
|||||||
|
|
||||||
# NyaaPy
|
# NyaaPy
|
||||||
|
|
||||||
Unofficial Python module to search into Nyaa.si
|
Unofficial Python module for Nyaa.si (WebScraping) and Nyaa.pantsu.cat (API wrapper)
|
||||||
|
|
||||||
Supports Python 3+
|
Supports Python 3+
|
||||||
|
|
||||||
|
Full docs available on [repo Wiki](https://github.com/JuanjoSalvador/NyaaPy/wiki)
|
||||||
|
|
||||||
* [Installation](#installation)
|
* [Installation](#installation)
|
||||||
* [Example](#example)
|
* [Example](#example)
|
||||||
* [Methods](#methods)
|
|
||||||
* [search()](#search)
|
|
||||||
* [news()](#news)
|
|
||||||
* [Categories and subcategories](#categories-and-subcategories)
|
|
||||||
* [Contributions and development](#contributons-and-development)
|
|
||||||
* [License](#license)
|
* [License](#license)
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install it using pip.
|
Install it using pip.
|
||||||
|
|
||||||
pip install nyaapy
|
pip install nyaapy
|
||||||
|
|
||||||
## Example
|
## Nyaa.si Example
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from NyaaPy import Nyaa
|
from NyaaPy import Nyaa
|
||||||
@@ -156,8 +152,6 @@ At this moment there isn't an official Nyaa.si API, so we only can make requests
|
|||||||
|
|
||||||
3. If you are ussing a clonned repo, please create a new branch named `patch-<username>-<version>`. Example: `patch-juanjosalvador-0.2`
|
3. If you are ussing a clonned repo, please create a new branch named `patch-<username>-<version>`. Example: `patch-juanjosalvador-0.2`
|
||||||
|
|
||||||
4. Always use the code into `src` folder, never the package.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT license.
|
MIT license.
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -1,7 +1,7 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(name='nyaapy',
|
setup(name='nyaapy',
|
||||||
version='0.4.3',
|
version='0.5.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',
|
||||||
|
|||||||
@@ -1,12 +1,3 @@
|
|||||||
from NyaaPy import Nyaa
|
from NyaaPy import Pantsu
|
||||||
|
|
||||||
# Nyaa.si results
|
print(Pantsu.search('koe no katachi', lang=["es", "ja"], category=[1, 3]))
|
||||||
nyaa_query = Nyaa.search()
|
|
||||||
|
|
||||||
nyaa_news = Nyaa.news(5)
|
|
||||||
|
|
||||||
if len(nyaa_query) > 0:
|
|
||||||
for result in nyaa_query:
|
|
||||||
print(result['name'])
|
|
||||||
else:
|
|
||||||
print('Nothing here!')
|
|
||||||
Reference in New Issue
Block a user