o
    ^ΓiU                     @   s.   d dl Zd dlmZmZ dddZdd ZdS )    N)get_db_configDB_NAMEc              
   C   s  d}zzt t}tjjdi |}| }d}||| f | }	|	r|	d }
g }g }|d || |durD|d || |durR|d || |dur`|d || |r|dd		| d
}||
 ||t
| |  |
W W |r|  S S d}||| ||||f |  |jW W |r|  S S  ty } z	td|  |d}~ww |r|  w w )zP
    Inserts or Updates an interview evaluation record based on session_id.
    Nz9SELECT id FROM interview_evaluation WHERE session_id = %sr   z	rating=%sz	advice=%szinterviewer_name=%szinterview_type=%sz UPDATE interview_evaluation SET z, z WHERE id = %sz
                INSERT INTO interview_evaluation 
                (session_id, rating, advice, interviewer_name, interview_type) 
                VALUES (%s, %s, %s, %s, %s)
            z[Interview Eval DB Error]  )r   r   mysql	connectorconnectcursorexecutefetchoneappendjointuplecommitclose	lastrowid	Exceptionprint)
session_idratingadviceinterviewer_nameinterview_typeconn	db_configr   	check_sqlrowlog_idupdate_fieldsparamssqler   r   =/home/air/goalskill_sales/back/app/models/interview_module.pyinsert_evaluation   s^   











r"   c              
   C   s   d}zcz?t d}tjjd	i |}|jdd}d}||| f | }|r7|d r7|d W W |r6|  S S W W |rA|  dS dS  tye } zt	d|  W Y d}~W |r_|  dS dS d}~ww |rm|  w w )
z
    Fetches the username from Sales_A_DB.user_profile_summary based on session_id.
    Returns 'Guest' if not found or error.
    N
Sales_A_DBT)
dictionaryz?SELECT username FROM user_profile_summary WHERE session_id = %susernameGuestz[Interview Profile Load Error] r   )
r   r   r   r   r   r	   r
   r   r   r   )r   r   r   r   r   r   r    r   r   r!   get_username_from_profileE   s8   


r'   )NN)mysql.connectorr   app.core.configr   r   r"   r'   r   r   r   r!   <module>   s   
@