From 3f2fa6efc7582c26ebb809e05ed3f3034ab56711 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Wed, 8 Jan 2025 20:11:00 -0500 Subject: [PATCH] Cleanb up data insert --- services/web/project/__init__.py | 86 ++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/services/web/project/__init__.py b/services/web/project/__init__.py index 78d65ff..1009941 100644 --- a/services/web/project/__init__.py +++ b/services/web/project/__init__.py @@ -104,22 +104,39 @@ engine = create_engine(dataUrl) @app.route("/") def hello_world(): -# mail.send( -# subject="Template example", -# receivers=["ameye@chiefsoft.com"], -# html_template="email/verify.html" -# ) + email="ameye+" + str( random.randint(1000, 99999)) + "@chiefsoft.com" + firstname="First" + str(random.randint(10, 100)) + lastname="Last" + str(random.randint(10, 100)); - send_register_mail('ameye@chiefsoft.com') -# msg = Message( -# 'Hello', -# sender ='message@chiefsoft.com', -# recipients = ['ses66181@gmail.com'] -# ) -# msg.body = 'Hello Flask message sent from Flask-Mail' -# mail.send(msg) + SELECT_INSERT = "SELECT uid, firstname , lastname , email FROM members_pending WHERE status = 0 AND email='" + email + "'" + print(SELECT_INSERT) + ADJUST_PREVIOUS = "UPDATE members_pending SET status = 3 WHERE status = 0 AND email='" + email + "'" + val_update = (email) + val_insert = (email, firstname, lastname) + INSERT_MEMBERS = "INSERT INTO members_pending(email,firstname,lastname) VALUES(%s,%s,%s)" + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(ADJUST_PREVIOUS) + cursor.execute(INSERT_MEMBERS, val_insert) + # connection.commit() +# last_row_id=cursor.lastrowid +# print('After Insert ::: ') +# #connection.insert_id() +# print(last_row_id) - return jsonify(action_data="sent") + SELECT_INSERT = "SELECT uid, firstname , lastname , email FROM members_pending WHERE status = 0 AND email='" + email + "'" + print(SELECT_INSERT) + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(SELECT_INSERT) + select_pendingRes = cursor.fetchall() + + print(select_pendingRes) + select_pending = json.dumps( [dict(ix) for ix in select_pendingRes] ) + print(select_pending) + array3 = json.loads(select_pending) + + return jsonify(action_data="sent", select_pending=array3) @app.route("/test/products") @@ -272,17 +289,44 @@ def start_register(): # values = ("john", "password123") # cursor.execute(query, values) # conn.commit() +# email="ameye+" + str( random.randint(1000, 99999)) + "@chiefsoft.com" +# firstname="First" + str(random.randint(10, 100)) +# lastname="Last" + str(random.randint(10, 100)); - INSERT_MEMBERS = "INSERT INTO members_pending(email,firstname,lastname) VALUES('"+email+"','"+firstname+"','"+lastname+"')" + SELECT_INSERT = "SELECT id,uid, firstname , lastname , email FROM members_pending WHERE status = 0 AND email='" + email + "'" + print(SELECT_INSERT) + ADJUST_PREVIOUS = "UPDATE members_pending SET status = 3 WHERE status = 0 AND email='" + email + "'" + val_update = (email) + val_insert = (email, firstname, lastname) + INSERT_MEMBERS = "INSERT INTO members_pending(email,firstname,lastname) VALUES(%s,%s,%s)" with connection: with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: - cursor.execute(INSERT_MEMBERS) - connection.commit() - last_row_id=cursor.lastrowid - print('After Insert ::: ') - print(last_row_id) + cursor.execute(ADJUST_PREVIOUS) + cursor.execute(INSERT_MEMBERS, val_insert) - send_register_mail(email) + print(SELECT_INSERT) + with connection: + with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: + cursor.execute(SELECT_INSERT) + select_pendingRes = cursor.fetchall() + + print(select_pendingRes) + select_pending = json.dumps( [dict(ix) for ix in select_pendingRes] ) + print(select_pending) + array3 = json.loads(select_pending) + last_row_id = array3[last_row_id] + + +# INSERT_MEMBERS = "INSERT INTO members_pending(email,firstname,lastname) VALUES('"+email+"','"+firstname+"','"+lastname+"')" +# with connection: +# with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cursor: +# cursor.execute(INSERT_MEMBERS) +# connection.commit() +# last_row_id=cursor.lastrowid +# print('After Insert ::: ') +# print(last_row_id) + + send_register_mail(email) return jsonify(hello="ameye signup path world", last_row_id=last_row_id) except Exception as e: