Issue #30 Improve the torrent objects

This commit is contained in:
Dolphin
2020-12-13 21:12:56 +01:00
parent d3b2892c1f
commit 9db8af3a60
7 changed files with 82 additions and 46 deletions

17
NyaaPy/torrent.py Normal file
View File

@@ -0,0 +1,17 @@
def json_to_class(data):
# We check if the data passed is a list or not
if isinstance(data, list):
object_list = []
for item in data:
object_list.append(Torrent(item))
# Return a list of Torrent objects
return object_list
else:
return Torrent(data)
# This deals with converting the dict to an object
class Torrent(object):
def __init__(self, my_dict):
for key in my_dict:
setattr(self, key, my_dict[key])