Sindbad~EG File Manager
from flask import session
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_
from core import app
# import boto3
# from botocore.exceptions import ClientError
engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600,future=True)
# engine = create_engine('')
class UserModel():
def __init__(self):
try:
self.meta = MetaData()
self.payments = Table("payments", self.meta ,autoload_with=engine)
except Exception as e:
print(e)
def insert_delegates(self, data, unique_id):
with engine.begin() as conn:
conn.execute(self.payments.insert(), data)
stmt = text("select p_id FROM payments WHERE unique_id = '"+unique_id+"';")
result = conn.execute(stmt)
output = result.fetchone()
if output:
last_p_id = output.p_id
return last_p_id
else:
return None
def get_delegate_by_pid(self,id):
with engine.connect() as conn:
# stmt = select([self.payments]).where(self.payments.c.p_id.in_([id]))
stmt = text("select * from payments where p_id = "+str(id)+";")
print("<< get_delegate_by_pid stmt from port 5001 user model >>")
result = conn.execute(stmt)
result = result.fetchone()
return dict(result._mapping) if result else None
# last_insert_id,payment_id
def update_payment_id(self,p_id,status, payment_id):
with engine.connect() as conn:
stmt = self.payments.update().values({"payment_status":status, "payment_id":payment_id}).where(self.payments.c.p_id.in_([p_id]))
result = engine.execute(stmt)
conn.commit()
return result
def get_users_email(self,email):
with engine.connect() as conn:
# stmt = self.payments.select().where(self.payments.c.email.in_([email]))
stmt = text("select * from payments where email = '"+email+"';")
result = conn.execute(stmt).one_or_none()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists