test for new function to get any statement from many companies; renamed functions

This commit is contained in:
2021-12-03 14:17:49 +01:00
parent 1f8104b1a0
commit ca360413c3
3 changed files with 59 additions and 32 deletions

View File

@ -3,6 +3,7 @@ MAIN_LOGGER_NAME = 'mwfin'
HTML_PARSER = 'html.parser'
DOMAIN = 'www.marketwatch.com'
BASE_URL = f'https://{DOMAIN}/investing/stock'
DEFAULT_CONCURRENT_BATCH_SIZE = 1
BS, IS, CF = 'Balance Sheet', 'Income Statement', 'Cash Flow Statement'
FIN_STMT_URL_SUFFIX = {

View File

@ -81,8 +81,8 @@ def extract_all_data(soup: BeautifulSoup) -> ResultDict:
@in_async_session
async def _get_financial_statement(statement: str, ticker_symbol: str, quarterly: bool = False,
session: ClientSession = None) -> ResultDict:
async def _get_single_company_fin_stmt(statement: str, ticker_symbol: str, quarterly: bool = False,
session: ClientSession = None) -> ResultDict:
"""
Returns data from the specified financial statement of the specified company.
"""
@ -93,6 +93,13 @@ async def _get_financial_statement(statement: str, ticker_symbol: str, quarterly
return extract_all_data(soup)
@in_async_session
async def _get_multi_companies_fin_stmt(statement: str, *ticker_symbols: str, quarterly: bool = False,
concurrent_batch_size: int = constants.DEFAULT_CONCURRENT_BATCH_SIZE,
session: ClientSession = None) -> Union[ResultDict, Dict[str, ResultDict]]:
pass
@in_async_session
async def get_balance_sheet(*ticker_symbols: str, quarterly: bool = False,
session: ClientSession = None) -> Union[ResultDict, Dict[str, ResultDict]]:
@ -100,9 +107,9 @@ async def get_balance_sheet(*ticker_symbols: str, quarterly: bool = False,
Returns data from the balance sheet of the specified company.
"""
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.BS, ticker_symbols[0], quarterly, session)
return await _get_single_company_fin_stmt(constants.BS, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.BS, sym, quarterly, session)
sym: await _get_single_company_fin_stmt(constants.BS, sym, quarterly, session)
for sym in ticker_symbols
}
@ -114,9 +121,9 @@ async def get_income_statement(*ticker_symbols: str, quarterly: bool = False,
Returns data from the income statement of the specified company.
"""
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.IS, ticker_symbols[0], quarterly, session)
return await _get_single_company_fin_stmt(constants.IS, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.IS, sym, quarterly, session)
sym: await _get_single_company_fin_stmt(constants.IS, sym, quarterly, session)
for sym in ticker_symbols
}
@ -128,9 +135,9 @@ async def get_cash_flow_statement(*ticker_symbols: str, quarterly: bool = False,
Returns data from the cash flow statement of the specified company.
"""
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.CF, ticker_symbols[0], quarterly, session)
return await _get_single_company_fin_stmt(constants.CF, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.CF, sym, quarterly, session)
sym: await _get_single_company_fin_stmt(constants.CF, sym, quarterly, session)
for sym in ticker_symbols
}
@ -139,9 +146,9 @@ async def get_cash_flow_statement(*ticker_symbols: str, quarterly: bool = False,
async def _get_single_company_financials(ticker_symbol: str, quarterly: bool = False,
session: ClientSession = None) -> Dict[str, ResultDict]:
return {
constants.BS: await _get_financial_statement(constants.BS, ticker_symbol, quarterly, session),
constants.IS: await _get_financial_statement(constants.IS, ticker_symbol, quarterly, session),
constants.CF: await _get_financial_statement(constants.CF, ticker_symbol, quarterly, session)
constants.BS: await _get_single_company_fin_stmt(constants.BS, ticker_symbol, quarterly, session),
constants.IS: await _get_single_company_fin_stmt(constants.IS, ticker_symbol, quarterly, session),
constants.CF: await _get_single_company_fin_stmt(constants.CF, ticker_symbol, quarterly, session)
}