drafted remaining functions

This commit is contained in:
Maximilian Fajnberg 2021-11-27 17:23:36 +01:00
parent f9745ff46d
commit 2380540659
3 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
HTML_PARSER = 'html.parser' HTML_PARSER = 'html.parser'
DOMAIN = 'www.marketwatch.com' DOMAIN = 'www.marketwatch.com'
BASE_URL = f'https://{DOMAIN}/investing/stock' BASE_URL = f'https://{DOMAIN}/investing/stock/'
BS, IS, CF = 'bs', 'is', 'cf' BS, IS, CF = 'bs', 'is', 'cf'
FIN_STMT_URL_SUFFIX = { FIN_STMT_URL_SUFFIX = {

View File

@ -84,7 +84,10 @@ async def _get_financial_statement(statement: str, ticker_symbol: str, quarterly
""" """
Returns data from the specified financial statement of the specified company. Returns data from the specified financial statement of the specified company.
""" """
pass q = '/quarter' if quarterly else ''
url = constants.BASE_URL + ticker_symbol + '/financials' + constants.FIN_STMT_URL_SUFFIX[statement] + q
soup = await soup_from_url(url, session)
return extract_all_data(soup)
async def get_balance_sheet(ticker_symbol: str, quarterly: bool = False, async def get_balance_sheet(ticker_symbol: str, quarterly: bool = False,
@ -92,7 +95,7 @@ async def get_balance_sheet(ticker_symbol: str, quarterly: bool = False,
""" """
Returns data from the balance sheet of the specified company. Returns data from the balance sheet of the specified company.
""" """
pass return await _get_financial_statement(constants.BS, ticker_symbol, quarterly, session)
async def get_income_statement(ticker_symbol: str, quarterly: bool = False, async def get_income_statement(ticker_symbol: str, quarterly: bool = False,
@ -100,7 +103,7 @@ async def get_income_statement(ticker_symbol: str, quarterly: bool = False,
""" """
Returns data from the income statement of the specified company. Returns data from the income statement of the specified company.
""" """
pass return await _get_financial_statement(constants.IS, ticker_symbol, quarterly, session)
async def get_cash_flow_statement(ticker_symbol: str, quarterly: bool = False, async def get_cash_flow_statement(ticker_symbol: str, quarterly: bool = False,
@ -108,7 +111,7 @@ async def get_cash_flow_statement(ticker_symbol: str, quarterly: bool = False,
""" """
Returns data from the cash flow statement of the specified company. Returns data from the cash flow statement of the specified company.
""" """
pass return await _get_financial_statement(constants.CF, ticker_symbol, quarterly, session)
async def get_company_financials(ticker_symbol: str, quarterly: bool = False, async def get_company_financials(ticker_symbol: str, quarterly: bool = False,
@ -116,4 +119,7 @@ async def get_company_financials(ticker_symbol: str, quarterly: bool = False,
""" """
Returns all fundamentals (balance sheet, income statement and cash flow statement) of the specified company. Returns all fundamentals (balance sheet, income statement and cash flow statement) of the specified company.
""" """
pass financials = await get_balance_sheet(ticker_symbol, quarterly, session)
financials.update(await get_income_statement(ticker_symbol, quarterly, session))
financials.update(await get_cash_flow_statement(ticker_symbol, quarterly, session))
return financials

View File

@ -104,7 +104,7 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
async def test__get_financial_statement(self, mock_soup_from_url, mock_extract_all_data): async def test__get_financial_statement(self, mock_soup_from_url, mock_extract_all_data):
mock_session = MagicMock() mock_session = MagicMock()
test_ticker, statement = 'bar', BS test_ticker, statement = 'bar', BS
test_url = f'{BASE_URL}/{test_ticker}/financials{FIN_STMT_URL_SUFFIX[statement]}' test_url = f'{BASE_URL}{test_ticker}/financials{FIN_STMT_URL_SUFFIX[statement]}'
mock_soup_from_url.return_value = mock_soup = MagicMock() mock_soup_from_url.return_value = mock_soup = MagicMock()
mock_extract_all_data.return_value = expected_output = {'foo': 'bar'} mock_extract_all_data.return_value = expected_output = {'foo': 'bar'}