implemented getting specific financial statement for multiple companies; fixed tests

This commit is contained in:
2021-11-28 17:07:23 +01:00
parent 1529df252c
commit e522897991
2 changed files with 37 additions and 22 deletions

View File

@ -90,28 +90,43 @@ async def _get_financial_statement(statement: str, ticker_symbol: str, quarterly
return extract_all_data(soup)
async def get_balance_sheet(ticker_symbol: str, quarterly: bool = False,
async def get_balance_sheet(*ticker_symbols: str, quarterly: bool = False,
session: ClientSession = None) -> ResultDict:
"""
Returns data from the balance sheet of the specified company.
"""
return await _get_financial_statement(constants.BS, ticker_symbol, quarterly, session)
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.BS, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.BS, sym, quarterly, session)
for sym in ticker_symbols
}
async def get_income_statement(ticker_symbol: str, quarterly: bool = False,
async def get_income_statement(*ticker_symbols: str, quarterly: bool = False,
session: ClientSession = None) -> ResultDict:
"""
Returns data from the income statement of the specified company.
"""
return await _get_financial_statement(constants.IS, ticker_symbol, quarterly, session)
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.IS, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.IS, sym, quarterly, session)
for sym in ticker_symbols
}
async def get_cash_flow_statement(ticker_symbol: str, quarterly: bool = False,
async def get_cash_flow_statement(*ticker_symbols: str, quarterly: bool = False,
session: ClientSession = None) -> ResultDict:
"""
Returns data from the cash flow statement of the specified company.
"""
return await _get_financial_statement(constants.CF, ticker_symbol, quarterly, session)
if len(ticker_symbols) == 1:
return await _get_financial_statement(constants.CF, ticker_symbols[0], quarterly, session)
return {
sym: await _get_financial_statement(constants.CF, sym, quarterly, session)
for sym in ticker_symbols
}
async def get_company_financials(*ticker_symbols: str, quarterly: bool = False,
@ -121,14 +136,14 @@ async def get_company_financials(*ticker_symbols: str, quarterly: bool = False,
"""
if len(ticker_symbols) == 1:
return {
constants.BS: await get_balance_sheet(ticker_symbols[0], quarterly, session),
constants.IS: await get_income_statement(ticker_symbols[0], quarterly, session),
constants.CF: await get_cash_flow_statement(ticker_symbols[0], quarterly, session)
constants.BS: await get_balance_sheet(ticker_symbols[0], quarterly=quarterly, session=session),
constants.IS: await get_income_statement(ticker_symbols[0], quarterly=quarterly, session=session),
constants.CF: await get_cash_flow_statement(ticker_symbols[0], quarterly=quarterly, session=session)
}
return {
sym: {
constants.BS: await get_balance_sheet(sym, quarterly, session),
constants.IS: await get_income_statement(sym, quarterly, session),
constants.CF: await get_cash_flow_statement(sym, quarterly, session)
constants.BS: await get_balance_sheet(sym, quarterly=quarterly, session=session),
constants.IS: await get_income_statement(sym, quarterly=quarterly, session=session),
constants.CF: await get_cash_flow_statement(sym, quarterly=quarterly, session=session)
} for sym in ticker_symbols
}