Conform to PEP8 style
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class Utils:
|
||||
def nyaa_categories(self, b):
|
||||
c = b.replace('/?c=', '')
|
||||
@@ -37,7 +38,7 @@ class Utils:
|
||||
"3": "Raw"
|
||||
}
|
||||
},
|
||||
"4": {
|
||||
"4": {
|
||||
"name": "Live Action",
|
||||
"subcats": {
|
||||
"1": "English-translated",
|
||||
@@ -46,14 +47,14 @@ class Utils:
|
||||
"4": "Raw"
|
||||
}
|
||||
},
|
||||
"5": {
|
||||
"5": {
|
||||
"name": "Pictures",
|
||||
"subcats": {
|
||||
"1": "Graphics",
|
||||
"2": "Photos"
|
||||
}
|
||||
},
|
||||
"6": {
|
||||
"6": {
|
||||
"name": "Software",
|
||||
"subcats": {
|
||||
"1": "Applications",
|
||||
@@ -61,10 +62,11 @@ class Utils:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
category_name = "{} - {}".format(categories[cat]['name'], categories[cat]['subcats'][subcat])
|
||||
except:
|
||||
category_name = "{} - {}".format(
|
||||
categories[cat]['name'], categories[cat]['subcats'][subcat])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return category_name
|
||||
@@ -107,7 +109,7 @@ class Utils:
|
||||
torrents.append(torrent)
|
||||
except IndexError as ie:
|
||||
pass
|
||||
|
||||
|
||||
return torrents
|
||||
|
||||
def parse_single(self, content):
|
||||
@@ -119,13 +121,14 @@ class Utils:
|
||||
for div in row.find_all('div', {'class': 'col-md-5'}):
|
||||
data.append(div.text.replace("\n", ""))
|
||||
|
||||
files = content[2].find('div', {'class', 'torrent-file-list'}).find_all('li')
|
||||
files = content[2].find('div',
|
||||
{'class', 'torrent-file-list'}).find_all('li')
|
||||
|
||||
for file in files:
|
||||
torrent_files.append(file.text)
|
||||
|
||||
|
||||
torrent['title'] = re.sub('\n|\r|\t', '', content[0].find('h3', {"class": "panel-title"}).text.replace("\n", ""))
|
||||
torrent['title'] = re.sub('\n|\r|\t', '', content[0].find('h3', {
|
||||
"class": "panel-title"}).text.replace("\n", ""))
|
||||
torrent['category'] = data[0]
|
||||
torrent['uploader'] = data[2]
|
||||
torrent['uploader_profile'] = "https://nyaa.si/user/{}".format(data[2])
|
||||
@@ -136,7 +139,8 @@ class Utils:
|
||||
torrent['leechers'] = data[5]
|
||||
torrent['completed'] = data[7]
|
||||
torrent['hash'] = data[8]
|
||||
torrent['description'] = re.sub('\t', '', content[1].find('div', {'id': 'torrent-description'}).text)
|
||||
torrent['description'] = re.sub('\t', '', content[1].find('div', {
|
||||
'id': 'torrent-description'}).text)
|
||||
torrent['files'] = torrent_files
|
||||
|
||||
return torrent
|
||||
@@ -158,14 +162,15 @@ class Utils:
|
||||
|
||||
if td.text.rstrip():
|
||||
block.append(td.text.rstrip())
|
||||
|
||||
|
||||
try:
|
||||
torrent = {
|
||||
'id': block[1].replace("/view/", ""),
|
||||
'category': Utils.sukebei_categories(self, block[0]),
|
||||
'url': "http://sukebei.nyaa.si{}".format(block[1]),
|
||||
'name': block[2],
|
||||
'download_url': "http://sukebei.nyaa.si{}".format(block[4]),
|
||||
'download_url': "http://sukebei.nyaa.si{}".format(
|
||||
block[4]),
|
||||
'magnet': block[5],
|
||||
'size': block[6],
|
||||
'date': block[7],
|
||||
@@ -173,9 +178,9 @@ class Utils:
|
||||
'leechers': block[9],
|
||||
'completed_downloads': block[10],
|
||||
}
|
||||
|
||||
|
||||
torrents.append(torrent)
|
||||
|
||||
|
||||
return torrents
|
||||
|
||||
def sukebei_categories(self, b):
|
||||
@@ -204,32 +209,36 @@ class Utils:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
category_name = "{} - {}".format(categories[cat]['name'], categories[cat]['subcats'][subcat])
|
||||
except:
|
||||
category_name = "{} - {}".format(
|
||||
categories[cat]['name'], categories[cat]['subcats'][subcat])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return category_name
|
||||
|
||||
# Pantsu Utils
|
||||
def query_builder(self, q, params):
|
||||
available_params = ["category", "page", "limit", "userID", "fromID", "status", "maxage", "toDate", "fromDate",\
|
||||
"dateType", "minSize", "maxSize", "sizeType", "sort", "order", "lang"]
|
||||
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":
|
||||
if (param != "category" and param != "status" and
|
||||
param != "lang"):
|
||||
query += "&{}={}".format(param, value)
|
||||
elif param == "category":
|
||||
query += "&c={}_{}".format(value[0], value[1])
|
||||
|
||||
|
||||
elif param == "status":
|
||||
query += "&s={}".format(value)
|
||||
|
||||
|
||||
elif param == "lang":
|
||||
for lang in value:
|
||||
query += "&lang={}".format(lang)
|
||||
|
||||
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user