U
    $ec
                     @   s   d dl Zd dlZd dlZd dlZd dlZd dlmZ d dlZejdddd e Z	e	
ej dZdZd	Zd
Zd
ZdZdZdd Zdd Zdd Ze  dS )    N)SSHTunnelForwarderzconnection.logz%(asctime)s %(message)sw)filenameformatfilemodez210.56.21.197ZdevuserZ	ubuntuhasrootZsmarthome_db	127.0.0.1c               
   C   sT   z t jdtttdatd W n. tk
rN }  zt	d|  W 5 d} ~ X Y nX dS )z|Connect to a MySQL server using the SSH tunnel connection
    
    :return connection: Global MySQL database connection
    r   )hostuserpasswddbzmysql connected successfulyzError while connecting to MySQLN)
pymysqlconnectdatabase_usernamedatabase_passworddatabase_name
connectionloggerdebugBaseExceptionerror)e r   %/var/www/html/flasktest/connection.pymysql_connect*   s    r   c                 C   s   t | tS )N)pdZread_sql_queryr   )Zsqlr   r   r   	run_query?   s    r   c                   C   s   t   dS )z*Closes the MySQL database connection.
    N)r   closer   r   r   r   mysql_disconnectB   s    r   )Zpandasr   timer   loggingZ	sshtunnelr   basicConfig	getLoggerr   setLevelDEBUGZssh_hostZssh_usernameZssh_passwordr   r   r   	localhostr   r   r   r   r   r   r   <module>   s,   
