two more functions implemented
This commit is contained in:
parent
f2abd8f2ce
commit
f9745ff46d
@ -61,14 +61,22 @@ def extract_row_data(tr: Tag) -> tuple[str, tuple[int]]:
|
||||
Returns the name of the item displayed in the table row (of a financial statement)
|
||||
as well as a number for each reporting period.
|
||||
"""
|
||||
pass
|
||||
item_name = str(tr.td.div.string).strip()
|
||||
data_div = tr.find_all('td')[-1].div.div
|
||||
values_str: str = data_div.attrs['data-chart-data']
|
||||
values = tuple(int(float(s)) for s in values_str.split(','))
|
||||
return item_name, values
|
||||
|
||||
|
||||
def extract_all_data(soup: BeautifulSoup) -> ResultDict:
|
||||
"""
|
||||
Extracts financials from the page.
|
||||
"""
|
||||
pass
|
||||
output = {constants.END_DATE: extract_end_dates(soup)}
|
||||
for row in find_relevant_table_rows(soup):
|
||||
row_data = extract_row_data(row)
|
||||
output[row_data[0]] = row_data[1]
|
||||
return output
|
||||
|
||||
|
||||
async def _get_financial_statement(statement: str, ticker_symbol: str, quarterly: bool = False,
|
||||
|
@ -73,9 +73,9 @@ class FunctionsTestCase(IsolatedAsyncioTestCase):
|
||||
mock_is_relevant_table_row.assert_has_calls([call(expected_output[0]), call(expected_output[1])])
|
||||
|
||||
def test_extract_row_data(self):
|
||||
test_table = self.test_soup.find('div', attrs={'class': 'financials'}).div.div.table
|
||||
test_row = self.test_soup.find('div', attrs={'class': 'financials'}).tbody.tr
|
||||
expected_output = ('Item_1', (11000000, -22000000))
|
||||
output = functions.extract_row_data(test_table.tbody.tr)
|
||||
output = functions.extract_row_data(test_row)
|
||||
self.assertTupleEqual(expected_output, output)
|
||||
|
||||
@patch.object(functions, 'extract_row_data')
|
||||
|
Loading…
Reference in New Issue
Block a user