def insert_actors_info(): """ Check if actor has username. If so saves id and username on youtube.csv. Returns: YoutubeAPI object if successful, None otherwise. """ yt_api = YoutubeAPI() yt_api.generate_folder() check = yt_api.generate_csv(clean=True) if check: with open('config/actors.json') as json_file: data = json.load(json_file) for item in data['channels']: if 'username' in item: if item['username']: result = yt_api.get_channel_info_by_username( item['username']) item['id'] = result['items'][0]['id'] yt_api.insert_value(column='channel_id', value=item['id'], search_cell='actor', search_value=item['actor'].replace( '\n', '')) yt_api.insert_value(column='username', value=item['username'], search_cell='actor', search_value=item['actor'].replace( '\n', '')) return yt_api return None
def test_insert_multiple_values_of_an_actor(self): yt_api = YoutubeAPI() insert_actors_info() result = yt_api.insert_multiple_values(column=['channel_id'], search_cell='actor', search_value='Frente Brasil' + ' Popular') result = yt_api.get_row(column='actor', value='Frente Brasil Popular') self.assertEqual(result, {'username': '', 'channel_id': 'null'})
def test_insert_value_of_an_actor(self): yt_api = YoutubeAPI() insert_actors_info() result = yt_api.insert_value(column='channel_id', value='UCX2Aanu4fGewmhP4rf5GQ3Q', search_cell='actor', search_value='Frente Brasil Popular') result = yt_api.get_row(column='actor', value='Frente Brasil Popular') self.assertEqual(result, { 'username': '', 'channel_id': 'UCX2Aanu4fGewmhP4rf5GQ3Q' }) self.clean_csv(yt_api) self.clean_folder(yt_api)
def test_clean_csv(self): yt_api = YoutubeAPI() self.assertTrue(yt_api.generate_csv(clean=True)) self.insert_value(yt_api) result = yt_api.get_row(column='actor', value='Frente Brasil Popular') self.assertEqual(result, { 'username': '', 'channel_id': 'UCX2Aanu4fGewmhP4rf5GQ3Q' }) self.assertTrue(yt_api.generate_csv(clean=True)) result = yt_api.get_row(column='actor', value='Frente Brasil Popular') self.assertEqual(result, {'username': '', 'channel_id': ''})
def __init__(self): with open('config/parameters.json') as data_file: parameters = json.load(data_file)['parameters'] self.user = YoutubeAPI() self._activities = { 'part': 'snippet,contentDetails', 'channelId': '', 'maxResults': '', 'publishedAfter': parameters['initial_date'], 'key': self.user._youtube_key } self._activities_extent = { 'part': 'snippet,contentDetails', 'channelId': '', 'maxResults': '', 'publishedAfter': '2018-01-01T00:00:01.45-03:00', 'publishedBefore': '', 'key': self.user._youtube_key } self._videos = { 'part': 'snippet,statistics,status,contentDetails', 'id': '', 'maxResults': '', 'key': self.user._youtube_key } self._search = { 'part': 'id,snippet', 'maxResults': '', 'type': '', 'relatedToVideoId': '', 'key': self.user._youtube_key } self._category = { 'part': 'id,snippet', 'hl': 'pt_BR', 'id': '', 'key': self.user._youtube_key }
def setUp(self): self._video = Videos() self._user = YoutubeAPI()
def test_check_data_of_an_actor(self): yt_api = insert_actors_info() result = YoutubeAPI().get_row(column='actor', value='Bancada Ativista') self.assertEqual(result, {'username': '', 'channel_id': ''})
def test_generate_youtube_folder(self): YoutubeAPI().generate_folder() self.assertTrue(os.path.exists(self._foldername))
def test_generate_youtube_csv(self): csv = YoutubeAPI().generate_csv() self.assertTrue(os.path.isfile(self._filename))