diff --git a/converter.py b/converter.py index efd05ec..57e141a 100644 --- a/converter.py +++ b/converter.py @@ -10,6 +10,8 @@ from correpy.parsers.brokerage_notes.parser_factory import ParserFactory from fastapi import UploadFile import re +import ntfy_service + account_id = '1590f1bb-b3ee-4dc8-ac46-bd1f15a83e87' logger = logging.getLogger(__name__) @@ -54,11 +56,21 @@ def convert_to_ghostfolio(brokerage_list: list, filename: str): transaction_type = 'SELL' name = re.sub(r'@|#' , '', transaction.security.name.strip()) + + symbol = '' + + try: + symbol = mappings.name_to_tickers[name.strip()].strip() + except: + logger.error(name.strip() + ' is not mapped.') + ntfy_service.send_notification(f'Failed to import: {name.strip()} is not mapped.') + + activity = {'accountId': account_id, 'comment': filename, 'date': reference_date, 'type': transaction_type, 'fee': fees, 'unitPrice': transaction.unit_price, 'quantity': transaction.amount, - 'symbol': mappings.name_to_tickers[name.strip()].strip(), + 'symbol': symbol, 'currency': 'BRL', 'dataSource': 'YAHOO'} activities['activities'].append(activity) diff --git a/ghostfolio_service.py b/ghostfolio_service.py index fb6ecf1..5914735 100644 --- a/ghostfolio_service.py +++ b/ghostfolio_service.py @@ -29,12 +29,7 @@ def import_activities(activities_json, filename: str): if len(response.json()['activities']) < 1: logger.info(f'No activity imported for {filename}') - print(f'No activity imported for {filename}') ntfy_service.send_notification(f'No activity imported for {filename}') else: ntfy_service.send_notification(f'Imported {len(response.json()['activities'])} activities from {filename}') - print(f'Imported {len(response.json()['activities'])} activities from {filename}') - - # print(json.dumps(response.json(), indent=4)) - return response.status_code diff --git a/mappings.py b/mappings.py index 6388413..b595d0f 100644 --- a/mappings.py +++ b/mappings.py @@ -1,6 +1,7 @@ name_to_tickers = { "BRASIL ON NM" : 'BBAS3.SA', "BRASIL ON EJ NM": 'BBAS3.SA', + "BRASIL ON ATZ NM": 'BBAS3.SA', "METAL LEVE ON NM": 'LEVE3.SA', "METAL LEVE ON ED NM": 'LEVE3.SA', "TRAN PAULIST PN N1": 'ISAE4.SA',