diff --git a/src/mw_stockfin/__init__.py b/src/mw_stockfin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/mw_stockfin/apps.py b/src/mw_stockfin/apps.py new file mode 100644 index 0000000..f0e50b3 --- /dev/null +++ b/src/mw_stockfin/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class MwStockfinConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'mw_stockfin' diff --git a/src/mw_stockfin/functions.py b/src/mw_stockfin/functions.py new file mode 100644 index 0000000..2c6e503 --- /dev/null +++ b/src/mw_stockfin/functions.py @@ -0,0 +1,33 @@ +from django_stockfin_db.models import FinancialPosition, ReportingPeriod, Company, Figure + +from mwfin import get_balance_sheet +from mwfin.functions import ResultDict, RowData + + +def end_date_to_reporting_period(date_str: str) -> ReportingPeriod: + """Convert an end date string into parameters for a ReportingPeriod, `get_or_create` the object and return it.""" + pass + + +def get_or_create_position(name: str, parent_position: FinancialPosition = None) -> FinancialPosition: + return FinancialPosition.objects.get_or_create(name=name, parent=parent_position) + + +def data_row_to_figures(company: Company, position: FinancialPosition, data: RowData): + pass + + +def save_single_result_dict(fin_stmt: str, symbol: str, result_dict: ResultDict): + company = Company.objects.get_or_create(symbol=symbol) + + +def result_dicts_to_db(fin_stmt: str, **data: ResultDict): + for symbol, result_dict in data.items(): + save_single_result_dict(fin_stmt, symbol, result_dict) + + +async def main(*symbols: str): + data = await get_balance_sheet(*symbols) + if len(symbols) == 1: + save_single_result_dict('BS', symbols[0], data) + result_dicts_to_db('BS', **data)