-
-
Notifications
You must be signed in to change notification settings - Fork 133
Description
Description of the bug
Running uvx pytr dl_docs does not complete and ends with an error message: see below.
To Reproduce
Steps to reproduce the behavior:
- Run command
uvx pytr -v debug dl_docs -l auto -s Downloaded\ Documents - See error
Traceback (most recent call last):
File "/Users/sergio/.local/share/uv/tools/pytr/bin/pytr", line 10, in <module>
sys.exit(main())
~~~~^^
File "/Users/sergio/.local/share/uv/tools/pytr/lib/python3.13/site-packages/pytr/main.py", line 504, in main
).do_dl()
~~~~~^^
File "/Users/sergio/.local/share/uv/tools/pytr/lib/python3.13/site-packages/pytr/dl.py", line 233, in do_dl
[Event.from_dict(ev) for ev in self.tl.events],
~~~~~~~~~~~~~~~^^^^
File "/Users/sergio/.local/share/uv/tools/pytr/lib/python3.13/site-packages/pytr/event.py", line 433, in from_dict
isin, shares, shares2, value, fees, taxes, note = cls._parse_type_dependent_params(event_type, event_dict)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/sergio/.local/share/uv/tools/pytr/lib/python3.13/site-packages/pytr/event.py", line 474, in _parse_type_dependent_params
note = cls._parse_card_note(event_dict)
File "/Users/sergio/.local/share/uv/tools/pytr/lib/python3.13/site-packages/pytr/event.py", line 796, in _parse_card_note
if eventTypeStr.startswith("card_"):
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'
Expected behavior
Execution of command completes without errors.
Environment
- OS: MacOS
- pytr version: 0.4.6
Additional context
Did some additional investigation in relation with the events that lead to the error and here is some preliminary feedback.
Debugging
Modified event.py file to dump event JSON for investigation purposes.
Here are examples of events for which the execution of the command choked.
Subtitle = "Zinszahlung"
"id": "8b8f4c47-a11c-3e8b-b53e-c71118e3136f",
"timestamp": "2024-06-18T15:36:14.249+0000",
"title": "",
"icon": "logos/XS1837288494/v2",
"avatar": {
"asset": "logos/XS1837288494/v2",
"badge": null
},
"badge": null,
"subtitle": "Zinszahlung",
"amount": {
"currency": "EUR",
"value": 11.25,
"fractionDigits": 2
},
"subAmount": null,
"status": "EXECUTED",
"action": {
"type": "timelineDetail",
"payload": "8b8f4c47-a11c-3e8b-b53e-c71118e3136f"
},
"cashAccountNumber": null,
"hidden": false,
"deleted": false,
"eventType": null,
"source": "timelineTransaction",
"details": {
... intentionally left blank ...
}
}
Subtitle = "Endgültige Fälligkeit"
"id": "494104e1-8210-3c19-85c5-5064de224a54",
"timestamp": "2024-06-19T18:06:42.086+0000",
"title": "",
"icon": "logos/DE0001104883/v2",
"avatar": {
"asset": "logos/DE0001104883/v2",
"badge": null
},
"badge": null,
"subtitle": "Endg\u00fcltige F\u00e4lligkeit",
"amount": {
"currency": "EUR",
"value": 1000.0,
"fractionDigits": 2
},
"subAmount": null,
"status": "EXECUTED",
"action": {
"type": "timelineDetail",
"payload": "494104e1-8210-3c19-85c5-5064de224a54"
},
"cashAccountNumber": null,
"hidden": false,
"deleted": false,
"eventType": null,
"source": "timelineTransaction",
"details": {
... intentionally left blank ...
}
}
Patching
Eventually, I came to the conclusion that the execution of the command failed due to eventType being null and no suitable mapping could be found.
Not knowing whether this makes sense, I proceeded with manually patching file event.py by adding 2 additional entries as follows:
subtitle_event_type_mapping = {
# Dividends
"Aktienprämiendividende": PPEventType.DIVIDEND,
"Bardividende": PPEventType.DIVIDEND,
"Bardividende korrigiert": PPEventType.DIVIDEND,
"Dividende": PPEventType.DIVIDEND,
"Dividende Wahlweise": PPEventType.DIVIDEND,
"Tilgung": PPEventType.DIVIDEND,
# Saveback
"Saveback": ConditionalEventType.SAVEBACK,
# Spinoff
"Aktiendividende": PPEventType.SPINOFF,
"Spin-off": PPEventType.SPINOFF,
"Zwischenvertrieb von Wertpapieren": PPEventType.SPINOFF,
# Split
"Aktiensplit": PPEventType.SPLIT,
"Bonusaktien": PPEventType.SPLIT,
# Swap
"Aufruf von Zwischenpapieren": PPEventType.SWAP,
"Reverse Split": PPEventType.SWAP,
"Teilrückzahlung ohne Reduzierung des Poolfaktors": PPEventType.SWAP,
"Zusammenschluss": PPEventType.SWAP,
# Taxes
"Vorabpauschale": PPEventType.TAXES,
# Trade invoices
"Kauforder": ConditionalEventType.TRADE_INVOICE,
"Limit-Buy-Order": ConditionalEventType.TRADE_INVOICE,
"Limit-Sell-Order": ConditionalEventType.TRADE_INVOICE,
"Limit Verkauf-Order neu abgerechnet": ConditionalEventType.TRADE_INVOICE,
"Round up": ConditionalEventType.TRADE_INVOICE,
"Sparplan ausgeführt": ConditionalEventType.TRADE_INVOICE,
"Stop-Sell-Order": ConditionalEventType.TRADE_INVOICE,
"Verkaufsorder": ConditionalEventType.TRADE_INVOICE,
"Wertlos": ConditionalEventType.TRADE_INVOICE,
# Added manually
"Zinszahlung": PPEventType.INTEREST,
"Endgültige Fälligkeit": PPEventType.DIVIDEND,
}
After patching the file locally as indicated above, the execution of the command completed.
Questions
I notice that most of the event handling and event type mapping logic seems to occur within file event.py.
In general, what is the suggested best practice for extending/modifying the mappings?
As I am not familiar with development nor code version management, I prefer to reach out to the community for help.