Skip to content

Commit

Permalink
Merge pull request #52 from RasaHQ/feature/ENG-1303_parse_amount_of_m…
Browse files Browse the repository at this point in the history
…oney

Replace hardcoded currency strings with a regex parsing [ENG-1303]
  • Loading branch information
maksim-m authored Aug 29, 2024
2 parents 262c711 + 60bb99e commit 25866cd
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit 25866cd

Please sign in to comment.