fix: apply club card format parsing to winner setting mechanism
- Updated parse_accounts_from_message() to support 'CARD ACCOUNT' format - Updated set_account_as_winner() to split by space before formatting - Added card number display in success/error messages - Now winner setting works with format '2521 45-59-19-91-23-80-37'
This commit is contained in:
@@ -99,26 +99,44 @@ def mask_account_number(account_number: str, show_last_digits: int = 4) -> str:
|
||||
|
||||
def parse_accounts_from_message(text: str) -> List[str]:
|
||||
"""
|
||||
Извлекает все валидные номера счетов из текста сообщения
|
||||
Извлекает все валидные номера счетов из текста сообщения.
|
||||
Поддерживает формат: "КАРТА СЧЕТ" (например "2521 11-22-33-44-55-66-77")
|
||||
или просто "СЧЕТ" (например "11-22-33-44-55-66-77")
|
||||
|
||||
Args:
|
||||
text: Текст сообщения
|
||||
|
||||
Returns:
|
||||
List[str]: Список найденных и отформатированных номеров счетов
|
||||
List[str]: Список найденных строк (может включать номер карты и счета через пробел)
|
||||
"""
|
||||
if not text:
|
||||
return []
|
||||
|
||||
accounts = []
|
||||
# Ищем паттерны счетов в тексте (7 пар цифр)
|
||||
pattern = r'\b\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}\b'
|
||||
matches = re.findall(pattern, text)
|
||||
|
||||
for match in matches:
|
||||
# Паттерн 1: номер карты (4 цифры) + пробел + счет (7 пар цифр)
|
||||
pattern_with_card = r'\b(\d{4})\s+(\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2})\b'
|
||||
matches_with_card = re.findall(pattern_with_card, text)
|
||||
|
||||
for card, account in matches_with_card:
|
||||
formatted = format_account_number(account)
|
||||
if formatted:
|
||||
full_account = f"{card} {formatted}"
|
||||
if full_account not in accounts:
|
||||
accounts.append(full_account)
|
||||
|
||||
# Паттерн 2: только счет (7 пар цифр) - для обратной совместимости
|
||||
pattern_only_account = r'\b\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}[-\s]?\d{2}\b'
|
||||
matches_only = re.findall(pattern_only_account, text)
|
||||
|
||||
for match in matches_only:
|
||||
# Проверяем, что этот счет еще не был добавлен как часть "карта + счет"
|
||||
formatted = format_account_number(match)
|
||||
if formatted and formatted not in accounts:
|
||||
accounts.append(formatted)
|
||||
if formatted:
|
||||
# Проверяем, нет ли уже этого счета с картой
|
||||
already_added = any(formatted in acc for acc in accounts)
|
||||
if not already_added and formatted not in accounts:
|
||||
accounts.append(formatted)
|
||||
|
||||
return accounts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user