improved the expression
Browse files
App/Messages/MessagesRoute.py
CHANGED
@@ -40,8 +40,11 @@ async def receive_message(request: Request):
|
|
40 |
|
41 |
|
42 |
def parse_message_content(text: str) -> Optional[dict]:
|
43 |
-
# Regular expression to capture the data from the message
|
44 |
-
pattern = r"(\w+)\sConfirmed\.You have received Tsh([\d,]+\.\d{2}) from (\d{12}) - ([A-Z ]+) on (\d{1,2}/\d{1,2}/\d{2}) at ([\d:]+ [APM]+).*?balance
|
|
|
|
|
|
|
45 |
|
46 |
matches = re.search(pattern, text)
|
47 |
if matches:
|
@@ -68,7 +71,6 @@ def parse_decimal(amount_str: str) -> float:
|
|
68 |
def parse_date(date_str: str, time_str: str) -> str:
|
69 |
# Combine date and time strings and parse into ISO format
|
70 |
datetime_str = f"{date_str} {time_str}"
|
71 |
-
# Adjust the format as per the actual format in the message
|
72 |
try:
|
73 |
dt = datetime.strptime(datetime_str, "%d/%m/%y %I:%M %p")
|
74 |
return dt.isoformat()
|
|
|
40 |
|
41 |
|
42 |
def parse_message_content(text: str) -> Optional[dict]:
|
43 |
+
# Regular expression to capture the data from the message, allowing for different types of spaces
|
44 |
+
pattern = r"(\w+)\sConfirmed\.You have received Tsh([\d,]+\.\d{2}) from (\d{12}) - ([A-Z ]+) on (\d{1,2}/\d{1,2}/\d{2}) at ([\d:]+ [APM]+).*?balance\sis\sTsh([\d,]+\.\d{2})"
|
45 |
+
|
46 |
+
# Replace non-breaking spaces and other whitespace characters with regular spaces in the input text
|
47 |
+
text = re.sub(r"\s+", " ", text)
|
48 |
|
49 |
matches = re.search(pattern, text)
|
50 |
if matches:
|
|
|
71 |
def parse_date(date_str: str, time_str: str) -> str:
|
72 |
# Combine date and time strings and parse into ISO format
|
73 |
datetime_str = f"{date_str} {time_str}"
|
|
|
74 |
try:
|
75 |
dt = datetime.strptime(datetime_str, "%d/%m/%y %I:%M %p")
|
76 |
return dt.isoformat()
|