def get_conn(db_path): """Get current database connection. Will create the database if needed. :param db_path: Path to the sqlite file. :type db_path: str """ table_needed = True if os.path.exists(db_path): table_needed = False # connect to the db, creating it if needed conn = sqlite3.connect(db_path) # if its a new db we also need to create the schema if table_needed: schema_path = os.path.abspath(os.path.join( os.path.dirname(__file__), os.pardir, 'resources', 'create_table.sql')) # create the users table with APP.app_context(): sql = file(schema_path, mode='r').read() conn.cursor().executescript(sql) conn.commit() conn.row_factory = sqlite3.Row return conn
def send_mail(sender, recipients, subject, text_body, html_body): """To send a single email from sender to receiver synchronously :param sender: Sender of the email. :type sender: str :param recipients: Recipients email address. :type recipients: list :param subject: Subject of the email. :type subject: str :param text_body: Text of the body. :type text_body: str :param html_body: HTML of the body. :type html_body: str """ # Get mail server configuration message = Message(subject=subject, sender=sender, recipients=recipients) message.body = text_body message.html = html_body with APP.app_context(): mail.send(message)