refactored base classes to have structure more similar to snscrape, made scraper 'get' methods return dataclasses or list of dataclasses rather than dicts

This commit is contained in:
Tristan Lee
2022-04-11 10:27:12 -05:00
parent 3fd841f76a
commit 44a673f889
5 changed files with 252 additions and 177 deletions

View File

@@ -23,7 +23,7 @@ KWARGS_LIST = [
('get_auth_token', []),
('get_channel_info', ['channel_name']),
('get_subscribers', ['channel_id', 'auth_token']),
('get_all_videos', ['channel_id']),
('get_raw_video_info_list', ['channel_id']),
('get_views', ['video_id', 'auth_token']),
('get_video_reactions', ['video_id', 'auth_token']),
('get_all_comments', ['video_id']),
@@ -34,12 +34,12 @@ KWARGS_LIST = [
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
@pytest.mark.parametrize( 'function_str,kwargs', KWARGS_LIST )
def test_minimal_init( resources, function_str, kwargs ):
@pytest.mark.parametrize('function_str,kwargs', KWARGS_LIST)
def test_minimal_init(resources, function_str, kwargs):
function = eval( f'api.{function_str}')
function_kwargs = { kwarg : resources[ kwarg ] for kwarg in kwargs }
function = eval(f'api.{function_str}')
function_kwargs = {kwarg: resources[kwarg] for kwarg in kwargs}
function( **function_kwargs )
function(**function_kwargs)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

View File

@@ -19,38 +19,35 @@ from polyphemus import base
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
class TestOdyseeChannel:
class TestOdyseeChannelScraper:
@pytest.fixture(autouse=True)
def test_simple_init(self, resources):
self.channel = base.OdyseeChannel(channel_name = resources['channel_name'])
self.scraper = base.OdyseeChannelScraper(channel_name = resources['channel_name'])
def test_get_entity(self):
self.scraper.get_entity()
def test_get_all_videos(self):
self.channel.get_all_videos()
self.scraper.get_all_videos()
def test_get_all_videos_and_comments(self):
self.channel.get_all_videos_and_comments()
self.scraper.get_all_videos_and_comments()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
class TestOdyseeVideo:
def test_process_raw_video_info(resources):
video = base.process_raw_video_info(raw_video_info = resources['full_video_info'], auth_token = resources['auth_token'])
@pytest.fixture(autouse=True)
def test_simple_init(self, resources):
self.video = base.OdyseeVideo(full_video_info = resources['full_video_info'])
def test_get_all_comments(self):
self.video.get_all_comments()
def test_get_recommended(self):
self.video.get_recommended()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
class TestOdyseeComment:
def test_get_recommended(resources):
video = base.process_raw_video_info(raw_video_info = resources['full_video_info'], auth_token = resources['auth_token'])
base.get_recommended(video = video)
@pytest.fixture(autouse=True)
def test_simple_init(self, resources):
self.comment = base.OdyseeComment(full_comment_info = resources['full_comment_info'])
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def test_process_raw_comment_info(resources):
base.process_raw_comment_info(raw_comment_info = resources['full_comment_info'])
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

View File

@@ -91,7 +91,7 @@ def resources():
normalized_name = NORMALIZED_NAME,
canonical_url = CANONICAL_URL,
full_video_info = FULL_VIDEO_INFO,
full_comment_info = {**COMMENT_INFO_LIST[0], **{'likes' : 8, 'dislikes' : 0}},
full_comment_info = {**COMMENT_INFO_LIST[0], **{'likes': 8, 'dislikes': 0}},
comment_info_list = COMMENT_INFO_LIST,
auth_token = get_auth_token())