def save_handler(): name = str(request.form["name"]) email = str(request.form["email"]) birthday = str(request.form["birthday"]) if name.strip() != "" and email.strip() != "" and birthday.strip() != "": db_config = Config.db() db_conn = mdb.connect(db_config["host"], db_config["user"], db_config["password"], db_config["name"]) db_cursor = db_conn.cursor() query = "INSERT IGNORE INTO users(name, email, birthday) VALUES(%s, %s, %s)" try: db_cursor.execute(query, (name, email, birthday)) db_conn.commit() except Exception as e: return render_template("form.html", error=e.message) else: return render_template("form.html", error="All fields are required") return render_template("thanks.html")
import smtplib import MySQLdb as mdb import datetime import pytz from etc import Config smtp_config = Config.smtp() db_config = Config.db() db_conn = mdb.connect(db_config["host"], db_config["user"], db_config["password"], db_config["name"]) to_addresses = [] try: query = "SELECT DISTINCT(email) from users" db_cursor = db_conn.cursor() db_cursor.execute(query) results = db_cursor.fetchall() if len(results) == 0: print "No emails to send" exit() for row in results: to_addresses.append(row[0])