Merge pull request #17 from JuanjoSalvador/no-pantsu-branch
No pantsu branch
This commit is contained in:
@@ -6,5 +6,4 @@ __url__ = 'http://juanjosalvador.me'
|
|||||||
__copyright__ = '2017 Juanjo Salvador'
|
__copyright__ = '2017 Juanjo Salvador'
|
||||||
__license__ = 'MIT license'
|
__license__ = 'MIT license'
|
||||||
|
|
||||||
from NyaaPy.nyaa import Nyaa
|
from NyaaPy.nyaa import Nyaa
|
||||||
from NyaaPy.nyaapantsu import NyaaPantsu
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import requests
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from NyaaPy.utils import Utils as utils
|
|
||||||
|
|
||||||
|
|
||||||
class NyaaPantsu():
|
|
||||||
'''
|
|
||||||
Make a query to nyaa.pantsu.cat using keyword as keyword.
|
|
||||||
Returns an array of OrderedDict with every result of the query.
|
|
||||||
Returns an empty array if no results.
|
|
||||||
'''
|
|
||||||
def search(keyword):
|
|
||||||
nyaapantsu_baseurl = "https://nyaa.pantsu.cat/feed?c=_&s=0&max=99999&userID=0&q="
|
|
||||||
|
|
||||||
request = requests.get(nyaa_baseurl + keyword)
|
|
||||||
response = xmltodict.parse(request.text)
|
|
||||||
|
|
||||||
results = []
|
|
||||||
|
|
||||||
try:
|
|
||||||
if type(response['rss']['channel']['item']) is collections.OrderedDict:
|
|
||||||
results.append(response['rss']['channel']['item'])
|
|
||||||
else:
|
|
||||||
results = response['rss']['channel']['item']
|
|
||||||
|
|
||||||
except KeyError as ex:
|
|
||||||
results = []
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
'''
|
|
||||||
Returns an array of OrderedDict with the n last updates of nyaa.pantsu.cat
|
|
||||||
'''
|
|
||||||
def news(n):
|
|
||||||
nyaa_baseurl = "https://nyaa.pantsu.cat/feed"
|
|
||||||
|
|
||||||
request = requests.get(nyaa_baseurl)
|
|
||||||
response = xmltodict.parse(request.text)
|
|
||||||
|
|
||||||
results = response['rss']['channel']['item']
|
|
||||||
|
|
||||||
return results[:n]
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
class Utils():
|
class Utils():
|
||||||
|
|
||||||
def get_categories(b):
|
def nyaa_categories(b):
|
||||||
c = b.replace('/?c=', '')
|
c = b.replace('/?c=', '')
|
||||||
cats = c.split('_')
|
cats = c.split('_')
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ class Utils():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
torrent = {
|
torrent = {
|
||||||
'category': Utils.get_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],
|
||||||
'download_url': "http://nyaa.si{}".format(block[4]),
|
'download_url': "http://nyaa.si{}".format(block[4]),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# NyaaPy
|
# NyaaPy
|
||||||
|
|
||||||
Unofficial Python module to search into Nyaa.si and nyaa.pantsu.cat.
|
Unofficial Python module to search into Nyaa.si
|
||||||
|
|
||||||
Supports Python 3+
|
Supports Python 3+
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ Install it using pip.
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from NyaaPy import Nyaa, NyaaPantsu
|
from NyaaPy import Nyaa
|
||||||
|
|
||||||
nyaa_query = Nyaa.search(keyword='koe no katachi 1080', category=1, subcategory=0, filters=0, page=0)
|
nyaa_query = Nyaa.search(keyword='koe no katachi 1080', category=1, subcategory=0, filters=0, page=0)
|
||||||
|
|
||||||
|
|||||||
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.0',
|
version='0.4.1',
|
||||||
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',
|
||||||
|
|||||||
@@ -2,10 +2,13 @@ from NyaaPy import Nyaa, NyaaPantsu
|
|||||||
|
|
||||||
# Nyaa.si results
|
# Nyaa.si results
|
||||||
def nyaa_search():
|
def nyaa_search():
|
||||||
nyaa_query = Nyaa.search(keyword='koe no katachi 1080', category=1, subcategory=0, filters=0, page=0)
|
try:
|
||||||
|
nyaa_query = Nyaa.search(keyword='koe no katachi 1080', category=1, subcategory=0, page=0)
|
||||||
|
|
||||||
for nyaa in nyaa_query:
|
for nyaa in nyaa_query:
|
||||||
print(nyaa)
|
print(nyaa)
|
||||||
|
except TypeError as te:
|
||||||
|
print(te)
|
||||||
|
|
||||||
def nyaa_news():
|
def nyaa_news():
|
||||||
news = Nyaa.news(number_of_results=5)
|
news = Nyaa.news(number_of_results=5)
|
||||||
@@ -15,22 +18,14 @@ def nyaa_news():
|
|||||||
# Nyaa.pantsu.cat results
|
# Nyaa.pantsu.cat results
|
||||||
def pantsu_search():
|
def pantsu_search():
|
||||||
pantsu_query = NyaaPantsu.search('new game!!')
|
pantsu_query = NyaaPantsu.search('new game!!')
|
||||||
if len(pantsu_query) > 0:
|
|
||||||
for result in pantsu_query:
|
|
||||||
print(result['title'])
|
|
||||||
else:
|
|
||||||
print('Nothing here!')
|
|
||||||
|
|
||||||
|
|
||||||
def pantsu_news():
|
def pantsu_news():
|
||||||
news = NyaaPantsu.news(5)
|
print(NyaaPantsu.news(1))
|
||||||
|
|
||||||
for result in news:
|
|
||||||
print(result['title'])
|
|
||||||
|
|
||||||
# Uncomment whatever you want to test
|
# Uncomment whatever you want to test
|
||||||
|
|
||||||
#nyaa_search()
|
#nyaa_search()
|
||||||
#pantsu_search()
|
#pantsu_search()
|
||||||
nyaa_news()
|
#nyaa_news()
|
||||||
#pantsu_news()
|
pantsu_news()
|
||||||
Reference in New Issue
Block a user