-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(banks): add trust bank credit card #184
Conversation
0a89331
to
64093cb
Compare
src/monopoly/constants/statement.py
Outdated
TRUST = ( | ||
rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+" | ||
+ SharedPatterns.DESCRIPTION | ||
+ SharedPatterns.AMOUNT_EXTENDED | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you add an optional capture group for suffix, it'll be able to catch the +682 in your statement -- the other transactions will default to negative
TRUST = (
rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
+ SharedPatterns.DESCRIPTION
+ r"(?P<suffix>\+)?"
+ SharedPatterns.AMOUNT
)
This means you won't need to modify the OPTIONAL_NEGATIVE_SYMBOL (I should probably put it only for the specific bank that needs it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the same time you can replace the description pattern with a custom one using a negative lookahead, so that it excludes totals:
TRUST = (
rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
+ r"(?P<description>(?:(?!Total outstanding balance).)*?)"
+ r"(?P<suffix>\+)?"
+ SharedPatterns.AMOUNT
)
This will then allow the safety check to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I wasn't familiar with the negative lookahead pattern until some searching. Is this a more readable pattern for descrpition?
+ r"(?P<description>(?:.(?!Total outstanding balance))*)"
I find lots of examples about negative lookahead but the "lookahead" is after some token. I cannot tell why the line you provide works because there's no token before the lookahead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with modifying the transaction pattern regex here, but the pattern you mentioned doesn't seem to work 😕
There is actually a token before, which is \s+
, but isn't reflected well in the multiline string unfortunately
it should work out to something like 12 Oct\s+(?!\s+Total outstanding balance)\s+.*
https://regex101.com/r/tQGJVE/1
src/monopoly/statements/base.py
Outdated
if include_prev and idx - 1 > 0: | ||
prev_line = lines[idx - 1] | ||
if prev_line: | ||
# if previous line is a transaction, it cannot be part of the description | ||
if not self.pattern.search(prev_line): | ||
prev_line_text = prev_line.strip() | ||
prev_line_start_pos = prev_line.find(prev_line_text.split(" ")[0]) | ||
# don't process line if the description across both lines | ||
# doesn't align with a margin of three spaces | ||
if ( | ||
abs(description_pos - prev_line_start_pos) | ||
<= include_prev_margin | ||
): | ||
description = prev_line_text + " " + description | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of a multiline transaction that isn't currently well handled? I looked at your example statement but everything appears on a single line
if total_amount_found: | ||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! It's weird that no other banks that I have so far give a total amount like this.
try: | ||
logger.debug("Running debit statement safety check for credit statement") | ||
return True | ||
if DebitStatement.perform_safety_check(self): | ||
return True | ||
# the try-catch is needed to prevent a SafetyCheckError from being raised | ||
# a more verbose exception is raised later | ||
except SafetyCheckError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with the new regex pattern this bit isn't needed anymore
@rapiz1 Thanks for raising the PR! A few comments, but otherwise this looks pretty good |
b868b5f
to
f517a7d
Compare
047286c
to
64785f7
Compare
add trust bank creditcard
I've attached an example statement in tests. It has "Previous Balance" and "Outstanding Balance" in transactions. I'm not sure if we should exclude them and enable safety check.
Notable difference for Trust credit card statement
+64.2
is CR. It's a prefix instead of suffix.Resolves #183