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

View File

@@ -1,4 +1,4 @@
from NyaaPy import Nyaa
from NyaaPy.nyaa import Nyaa
from pprint import pprint
from datetime import datetime
import json
@@ -17,27 +17,46 @@ dt_latest_torrents_begin = datetime.now()
latest_torrents = nyaa.last_uploads(100)
dt_latest_torrents_end = datetime.now()
with open("test_files/nyaa_latest_torrent_test.json", 'w') as f:
json.dump(latest_torrents, f)
for torrent in latest_torrents:
try:
# This prints it as byte like objects since unicode is fun
f.write(str(torrent.name.encode('utf-8')) + '\n')
except AttributeError:
f.write('No name found for this torrent')
# Search some nasty stuff
dt_search_begin = datetime.now()
test_search = nyaa.search("kimi no na wa")
dt_search_end = datetime.now()
with open("test_files/nyaa_search_test.json", 'w') as f:
json.dump(test_search, f)
for torrent in test_search:
try:
# This prints it as byte like objects since unicode is fun
f.write(str(torrent.name.encode('utf-8')) + '\n')
except AttributeError:
f.write('No name found for this torrent')
# Get first torrent from found torrents
dt_single_torrent_begin = datetime.now()
single_torrent = nyaa.get(test_search[0]["id"])
single_torrent = test_search[0]
dt_single_torrent_end = datetime.now()
with open("test_files/nyaa_single_torrent_test.json", 'w') as f:
json.dump(single_torrent, f)
try:
# This prints it as byte like objects since unicode is fun
f.write(str(torrent.name.encode('utf-8')) + '\n')
except AttributeError:
f.write('No name found for this torrent')
dt_user_begin = datetime.now()
user_torrents = nyaa.get_user("HorribleSubs")
dt_user_end = datetime.now()
with open("test_files/nyaa_single_user_test.json", 'w') as f:
json.dump(user_torrents, f)
for torrent in user_torrents:
try:
# This prints it as byte like objects since unicode is fun
f.write(str(torrent.name.encode('utf-8')) + '\n')
except AttributeError:
f.write('No name found for this torrent')
print(
"Latest torrents time:",