import os
import contextlib
# import mysql.connector

@contextlib.contextmanager
def get_mysql_conn(db):
    """
    Context manager to automatically close DB connection.
    We retrieve credenrials from Enviroment variables
    """
    conn = mysql.connector.connect(host = os.environ.get('MYSQL_HOST'),
        user=os.environ.get('MYSQL_USER'), password=os.environ.get('MYSQL_PWD'), 
        database=db)

    try:
        yield conn
    finally:
        conn.close()


def main():
    pass

if __name__ == '__main__':
    main()