Skip to content

Commit 8470e6e

Browse files
committed
summary parser: parse scheme names running into multiple lines
1 parent 3c04464 commit 8470e6e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

casparser/process/cas_summary.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
StatementPeriod,
1414
)
1515

16-
from .regex import SUMMARY_DATE_RE, SUMMARY_ROW_RE
16+
from .regex import SCHEME_TAIL_RE, SUMMARY_DATE_RE, SUMMARY_ROW_RE
1717
from .utils import isin_search
1818

1919

@@ -43,6 +43,11 @@ def process_summary_text(text):
4343
for line in lines:
4444
if len(folios) > 0 and re.search("Total", line, re.I):
4545
break
46+
scheme_tail = ""
47+
if m := re.search(SCHEME_TAIL_RE, line, re.DOTALL | re.MULTILINE):
48+
scheme_tail = m.group(1).strip()
49+
line = line.replace(scheme_tail, "")
50+
scheme_tail = re.sub(r"\s+", " ", scheme_tail).strip()
4651
if m := re.search(SUMMARY_ROW_RE, line, re.DOTALL | re.MULTILINE | re.I):
4752
folio = m.group("folio").strip()
4853
if current_folio is None or current_folio != folio:
@@ -55,7 +60,10 @@ def process_summary_text(text):
5560
PANKYC="N/A",
5661
schemes=[],
5762
)
58-
scheme = re.sub(r"\(formerly.+?\)", "", m.group("name"), flags=re.I | re.DOTALL).strip()
63+
scheme = m.group("name")
64+
if scheme_tail != "":
65+
scheme = " ".join([scheme, scheme_tail])
66+
scheme = re.sub(r"\(formerly.+?\)", "", scheme, flags=re.I | re.DOTALL).strip()
5967
rta = m.group("rta").strip()
6068
rta_code = m.group("code").strip()
6169
isin_ = m.group("isin")

casparser/process/regex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
TRANSACTION_RE3 = rf"{date_re}\t\t([^0-9].*)\t\t{amt_re}(?:\t\t{amt_re}\t\t{amt_re}\t\t{amt_re})*"
4545
DESCRIPTION_TAIL_RE = r"(\n.+?)(\t\t|$)"
4646
DIVIDEND_RE = r"(?:div\.|dividend|idcw).+?(reinvest)*.*?@\s*Rs\.\s*([\d\.]+)(?:\s+per\s+unit)?"
47+
SCHEME_TAIL_RE = r"(\n.+)$"

0 commit comments

Comments
 (0)