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

Replace hardcoded currency strings with a regex parsing [ENG-1303] #52

Merged
merged 1 commit into from
Aug 29, 2024
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
6 changes: 5 additions & 1 deletion actions/execute_transfer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Any, Dict
from datetime import datetime
from rasa_sdk import Action, Tracker
Expand All @@ -6,6 +7,9 @@
from actions.db import get_account, write_account, add_transaction, Transaction


AMOUNT_OF_MONEY_REGEX = re.compile(r"\d*[.,]*\d+")


class ExecuteTransfer(Action):

def name(self) -> str:
Expand All @@ -25,7 +29,7 @@ def run(self, dispatcher: CollectingDispatcher,
if recipient == "Jack":
return [SlotSet("transfer_money_transfer_successful", False)]

amount_of_money_value = float(amount_of_money.replace("$", "").replace("USD", "").strip())
amount_of_money_value = float(re.findall(AMOUNT_OF_MONEY_REGEX, amount_of_money)[0])
account.funds -= amount_of_money_value
new_transaction = \
Transaction(datetime=datetime.now().isoformat(), recipient=recipient,
Expand Down
Loading