import pymysql import os import logging def getConnection() -> pymysql.Connection: """ Get a connection to SQL. This function is used on the vServer for local testing @return: pymysql connection object """ try: if os.getenv('IS_RASPI'): conn = pymysql.connect( user=os.environ['VSERVER_SQL_USER'], password=os.environ['VSERVER_SQL_PASSWORD'], host=os.environ['VSERVER_SQL_SERVER'], port=3306, database='ServerDowntimeMonitoring' ) else: conn = pymysql.connect( user=os.environ['PADDY_SQL_USER'], password=os.environ['PADDY_SQL_PASSWORD'], host=os.environ['SQL_SERVER'], port=3306, database='ServerDowntimeMonitoring' ) return conn except pymysql.Error as e: logging.error('SQL Connection error: %s', e) return None