Skip to content
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

Fix: Parse single line BOC credit bill #20

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions boc_credit_card/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,43 +109,46 @@ def extract_text_entries(self):
):
begin = False
elif begin:
# Is it a date line?
# Match date part first
# card number can be empty
if re.match(
m = re.match(
r"[0-9]+-[0-9]+-[0-9]+\n[0-9]+-[0-9]+-[0-9]+(\n[0-9]+)?",
content,
re.MULTILINE,
):
)
if m:
lines = content.split("\n")
trans_date = lines[0]
post_date = lines[1]
description = ""
else:
# Otherwise: Description/Deposit/Expenditure
description += content + "\n"
done = False
if x1 > 500:
# Expenditure found
expense = True
done = True
elif x1 > 400:
# Deposit found
expense = False
done = True
if done:
desc_lines = description.split("\n")
orig_narration = "".join(desc_lines[:-2])
value = desc_lines[-2]
entry = [
currency,
trans_date,
post_date,
card_number,
orig_narration,
value if not expense else "",
value if expense else "",
]
text_entries.append(entry)
# After date part matched, continue to match the rest
content = content[m.end() :]

# Description/Deposit/Expenditure
description += content + "\n"
done = False
if x1 > 500:
# Expenditure found
expense = True
done = True
elif x1 > 400:
# Deposit found
expense = False
done = True
if done:
desc_lines = description.split("\n")
orig_narration = "".join(desc_lines[:-2])
value = desc_lines[-2]
entry = [
currency,
trans_date,
post_date,
card_number,
orig_narration,
value if not expense else "",
value if expense else "",
]
text_entries.append(entry)

elif self.type == "email":
for lineno, card in enumerate(self.body.select("div.bill_card_detail")):
Expand Down