async def get(self, table_name: outer.TableName) -> pd.DataFrame: """Получение дивидендов для заданного тикера.""" ticker = self._log_and_validate_group(table_name, outer.CONOMY) html = await _get_html(ticker) cols_desc = _get_col_desc(ticker) df = parser.get_df_from_html(html, TABLE_INDEX, cols_desc) df = df.dropna() df = df.sort_index(axis=0) return df.groupby(lambda date: date).sum()
async def __call__(self, ticker: str) -> Optional[pd.DataFrame]: """Получение дивидендов для заданного тикера.""" self._logger(ticker) url = _prepare_url(ticker) html = await _get_page_html(url) cols_desc = _get_col_desc(ticker) try: df = parser.get_df_from_html(html, TABLE_NUM, cols_desc) except description.ParserError: return None return description.reformat_df_with_cur(df, ticker)
async def __call__(self, ticker: str) -> Optional[pd.DataFrame]: """Получение дивидендов для заданного тикера.""" self._logger(ticker) cols_desc = get_col_desc(ticker) url = "".join([URL_START, ticker[:-3], URL_END]) html = await _load_ticker_page(url) try: df = parser.get_df_from_html(html, 0, cols_desc) except description.ParserError: return None df = df.groupby(lambda date: date).sum() df[col.CURRENCY] = col.USD return df
async def __call__(self, ticker: str) -> Optional[pd.DataFrame]: """Получение дивидендов для заданного тикера.""" self._logger(ticker) try: # На некоторых компьютерах/операционных системах Chromium перестает реагировать на команды # Поэтому загрузка принудительно приостанавливается html = await asyncio.wait_for(_get_html(ticker), timeout=CHROMIUM_TIMEOUT) except (errors.TimeoutError, asyncio.exceptions.TimeoutError): return None cols_desc = _get_col_desc(ticker) df = parser.get_df_from_html(html, TABLE_INDEX, cols_desc) df = df.dropna() df = self._sort_and_agg(df) df[col.CURRENCY] = col.RUR return df
def test_get_df_from_html(mocker): """Тестирование последовательности вызовов.""" fake_get_table_from_html = mocker.patch.object(parser, "_get_table_from_html") fake_get_raw_df = mocker.patch.object(parser, "_get_raw_df") fake_validate_header = mocker.patch.object(parser, "_validate_header") fake_get_selected_col = mocker.patch.object(parser, "_get_selected_col") df_rez = parser.get_df_from_html("test_html", 2, [DESC_SINGLE_HEADER]) fake_get_table_from_html.assert_called_once_with("test_html", 2) fake_get_raw_df.assert_called_once_with( fake_get_table_from_html.return_value, [DESC_SINGLE_HEADER], ) fake_validate_header.assert_called_once_with( fake_get_raw_df.return_value.columns, [DESC_SINGLE_HEADER], ) fake_get_selected_col.assert_called_once_with( fake_get_raw_df.return_value, [DESC_SINGLE_HEADER], ) assert df_rez is fake_get_selected_col.return_value
async def __call__(self, ticker: str) -> Optional[pd.DataFrame]: """Получение дивидендов для заданного тикера.""" self._logger(ticker) cols_desc = get_col_desc(ticker) url = _prepare_url(ticker) try: html = await parser.get_html(url) except description.ParserError: return None try: table_index = _find_table_n(html) except description.ParserError: return None try: df = parser.get_df_from_html(html, table_index, cols_desc) except description.ParserError: return None return description.reformat_df_with_cur(df, ticker)