From bf01a922f0cddcec3e1105abadc24b8d9e277d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20N=C3=A1n=C3=A1si?= Date: Wed, 22 Jan 2020 19:07:38 +0100 Subject: [PATCH] Made few tests --- NyaaPy/nyaa.py | 8 +++----- NyaaPy/utils.py | 1 - tests/test.py | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/NyaaPy/nyaa.py b/NyaaPy/nyaa.py index 9165c37..c4ec563 100644 --- a/NyaaPy/nyaa.py +++ b/NyaaPy/nyaa.py @@ -46,13 +46,11 @@ class Nyaa: def get(self, id): r = requests.get("{}/view/{}".format(self.URI, id)) r.raise_for_status() - # ! Description not working TODO - # with open("test.html", "w") as f: - # f.write(r.text) + return utils.parse_single(request_text=r.text) def get_user(self, username): r = requests.get("{}/user/{}".format(self.URI, username)) - soup = BeautifulSoup(r.text, 'html.parser') + r.raise_for_status() - return utils.parse_nyaa(soup.select('table tr'), limit=None) + return utils.parse_nyaa(request_text=r.text, limit=None) diff --git a/NyaaPy/utils.py b/NyaaPy/utils.py index fbbbdf0..0c837b1 100644 --- a/NyaaPy/utils.py +++ b/NyaaPy/utils.py @@ -4,7 +4,6 @@ import re from lxml import etree -from pprint import pprint def nyaa_categories(b): diff --git a/tests/test.py b/tests/test.py index caf5875..2a5f5a4 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,22 +1,52 @@ from NyaaPy import Pantsu, Nyaa from pprint import pprint +from datetime import datetime # pantsu = Pantsu() nyaa = Nyaa() # Get fresh torrents -print("Latest torrents:") -latest_torrents = rnyaa.last_uploads(5) +dt_latest_torrents_begin = datetime.now() +latest_torrents = nyaa.last_uploads(100) +dt_latest_torrents_end = datetime.now() # I'd like to watch Tenki no ko, but not uploaded yet. -print("Search results for Kimi no Na wa:") +dt_search_begin = datetime.now() test_search = nyaa.search("Kimi no Na wa") -pprint(test_search) +dt_search_end = datetime.now() +# pprint(test_search) # Get first torrent from found torrents -print("First result torrent info:") +# print("First result torrent info:") +dt_single_torrent_begin = datetime.now() single_torrent = nyaa.get(test_search[0]["id"]) -pprint(single_torrent) +dt_single_torrent_end = datetime.now() +#pprint(single_torrent) + +dt_user_begin = datetime.now() +user_torrents = nyaa.get_user("Lilith-Raws") +dt_user_end = datetime.now() +#pprint(user_torrents) + +print( + "Latest torrents time:", + (dt_latest_torrents_end - dt_latest_torrents_begin).microseconds / 1000, + "msec") +print( + "Test search time:", + (dt_search_end - dt_search_begin).microseconds/ 1000, + "msec" +) +print( + "Single torrent time:", + (dt_single_torrent_end - dt_single_torrent_begin).microseconds / 1000, + "msec" +) +print( + "Single user time:", + (dt_user_end - dt_user_begin ).microseconds / 1000, + "msec" +) """ print(pantsu.search(keyword='koe no katachi',