Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
from core.library.helper import Helper
import json
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600,future=True)
class UserModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
self.payments = Table("payments", self.meta, autoload_with=engine)
except Exception as e:
print(e)
# insert user
def insertUser(self,data):
with engine.connect() as conn:
result = conn.execute(self.users.insert(), data)
# get pk
# user_id = [r for r in result.inserted_primary_key] if result.inserted_primary_key else None
conn.commit()
user_id = result.lastrowid
stmt = text("select * from users where user_id = "+str(user_id)+" ;")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else:
return None
return result.lastrowid
def updateUser(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
result = conn.execute(stmt)
conn.commit()
return result
def getUserByUserID(self,user_id):
with engine.connect() as conn:
stmt = text("select u.* from users u where u.user_id = "+str(user_id)+" ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def savePayRecord(self,user_id,data_for_user,data_for_payment) :
with engine.connect() as conn:
stmt = self.users.update().values(data_for_user).where(self.users.c.user_id.in_([user_id]))
result_1 = conn.execute(stmt)
conn.commit()
result_2 = conn.execute(self.payments.insert(), data_for_payment)
conn.commit()
return "success"
def getDataforPayments(self,user_id,unique_id):
with engine.connect() as conn:
stmt = text("select u.user_id,u.prefix,u.full_name,u.email,u.mobile ,p.payment_status,p.unique_id ,p.amount,p.updated_at from users u "
+ " inner join payments p on p.user_id = u.user_id where u.user_id = " +str(user_id)+ " and p.unique_id = '"+unique_id+"' ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def getPaymentByUniqueId(self,email,unique_id):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("select u.user_id,u.prefix,u.full_name,u.email,u.mobile ,p.payment_status,p.unique_id ,p.amount,p.updated_at from users u "
+ " inner join payments p on p.user_id = u.user_id where u.email = '" +email+ "' and p.unique_id = '"+unique_id+"' ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def checkAlreadyPaid(self,user_id) :
with engine.connect() as conn:
stmt = text("select u.user_id,u.prefix,u.full_name,u.email,u.mobile ,p.payment_status,p.unique_id ,p.amount,p.updated_at from users u "
+ " inner join payments p on p.user_id = u.user_id where u.user_id = "+str(user_id)+" and p.payment_status = 'success' ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def updatePayments(self,unique_id,data):
with engine.connect() as conn:
stmt = self.payments.update().values(data).where(self.payments.c.unique_id.in_([unique_id]))
result = conn.execute(stmt)
conn.commit()
return result
def updateOtpAndGetUser(self,user_id,data):
with engine.connect() as conn:
stmt_1 = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
result = conn.execute(stmt_1)
conn.commit()
stmt = text("select u.* from users u where u.user_id = "+str(user_id)+" ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
###################
def get_users_email_data(self,email,conf_id):
with engine.connect() as conn:
stmt = text(f"select * from users where email = '{email}' and conf_id ={conf_id} order by user_id asc limit 1 ;")
result = conn.execute(stmt).fetchone()
return dict(result._mapping) if result else None
def update_member(self,user_id,data):
with engine.connect() as conn:
stmt = self.users.update().values(data).where(self.users.c.user_id.in_([user_id]))
result = conn.execute(stmt)
conn.commit()
return result
def get_otp_random(self,user_id):
with engine.connect() as conn:
stmt = text("select otp from users where user_id = {} ".format(user_id))
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_member(self,user_id):
with engine.connect() as conn:
stmt = text("select u.* from users u where u.user_id = "+str(user_id)+" ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def get_video_link(self):
with engine.connect() as conn:
stmt = text("select * from video_table where is_active = 1 order by order_by asc ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_video_linkByVideoId(self,video_id):
with engine.connect() as conn:
stmt = text("select * ,(select ifnull(min(video_id),0) from video_table where is_active = 1) as min_video_id,(select ifnull(max(video_id), 0) from video_table where is_active = 1) as max_video_id,"
+ "(select video_id from video_table where is_active = 1 and video_id > "+str(video_id)+" order by order_by asc limit 1) as next_video_id,"
+ "(select video_id from video_table where is_active = 1 and video_id < "+str(video_id)+" order by order_by desc limit 1) as previous_video_id "
+ "from video_table where video_id = "+str(video_id)+" and is_active = 1 order by order_by asc ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def getDataForDay(self,conf_id):
with engine.connect() as conn:
conn = engine.connect()
# stmt_1 = text("set sql_mode = '' ;")
conn.execute(text("SET SESSION sql_mode = (SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));"))
stmt = text(f"SELECT program_day, hall,session_date,session_time from video_table where is_active >0 and conf_id={conf_id} group by program_day order by program_day asc; ")
print("---stmt---",stmt)
# conn.execute(stmt_1)
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
#SELECT * from video_table where program_day =1 and is_active >0 ;
def getDataByDay(self,program_day):
with engine.connect() as conn:
conn = engine.connect()
stmt = text("SELECT * from video_table where program_day = "+str(program_day)+" and is_active >0 order by hall asc ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_video_linkByVideoIdAndDay(self,video_id,program_day):
with engine.connect() as conn:
# stmt = text("select * from video_table where video_id = "+str(video_id)+" and is_active = 1 order by order_by asc ; ")
stmt = text("select * ,(select ifnull(min(video_id),0) from video_table where program_day = "+str(program_day)+" and is_active = 1) as min_video_id,(select ifnull(max(video_id), 0) from video_table where program_day = "+str(program_day)+" and is_active = 1) as max_video_id,"
+ "(select video_id from video_table where program_day = "+str(program_day)+" and is_active = 1 and video_id > "+str(video_id)+" order by order_by asc limit 1) as next_video_id,"
+ "(select video_id from video_table where program_day = "+str(program_day)+" and is_active = 1 and video_id < "+str(video_id)+" order by order_by desc limit 1) as previous_video_id "
+ "from video_table where program_day = "+str(program_day)+" and video_id = "+str(video_id)+" and is_active = 1 order by order_by asc ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def getDelegates(self):
with engine.connect() as conn:
stmt = text("select user_id,full_name,email ,mobile,delegate_no, mc_number from users where email like '%numerotec%' and email is not null and delegate_no is not null and full_name is not null; ")
# stmt = text("select user_id,full_name,email ,mobile,delegate_no, mc_number from users where email is not null and delegate_no is not null and full_name is not null; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
app.jinja_env.globals.update(UserModel=UserModel)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists