�
Ek�h � �, � d dl Z d dlZdedededefd�Zy)� N�name�email�dob�returnc �� � d}g d�}g }t j j |� }|rF t |dd�� 5 }t j
|� }|D ] } |j
| � � ddd� |D ]; }|j dd� j � |j � k( s�5d |� d
�c S t |dd�� 5 }t j ||�� }|s|j � |j | ||d�� ddd� d
| � d|� d|� d�S # 1 sw Y ��xY w# t $ r}
t d|
� �� Y d}
~
��d}
~
ww xY w# 1 sw Y �ExY w# t $ r}
d| � d|
� �cY d}
~
S d}
~
ww xY w)a&
Registers a new user by saving their name, email, and date of birth (DOB)
to a local CSV file named 'registration.csv'.
Prevents duplicate registrations based on the email address.
Args:
name (str): The name of the user.
email (str): The email address of the user.
dob (str): The date of birth of the user (e.g., 'YYYY-MM-DD').
Returns:
str: A confirmation message indicating whether the registration was successful,
or a message indicating that the user is already registered.
zregistration.csv)�Namer r �r� )�newlineNz3Warning: Could not read existing registration.csv: r z&Registration failed: User with email 'z' is already registered.�a)�
fieldnameszUser 'z&' registered successfully with email 'z' and DOB 'z'.zError registering user 'z': )�os�path�isfile�open�csv�
DictReader�append� Exception�print�get�lower�
DictWriter�writeheader�writerow)
r r r � file_pathr
�existing_users�file_exists�csvfile�reader�row�e�user�writers
�2/home/pallavi/Documents/mcp_project/tools/store.py�
store_datar&