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)
class UserModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload=True, autoload_with=engine)
self.payments = Table("payments", self.meta, autoload=True, 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
user_id = result.lastrowid
conn.commit()
stmt_2 = text("select * from users where user_id = "+str(user_id)+" ;")
result_2 = conn.execute(stmt_2).one_or_none()
result_2 = dict(result_2._mapping) if result_2 else None
if result_2 :
return result_2
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)+" ; ")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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)
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+"' ;")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results else None
def getPaymentByUniqueId(self,email,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.email = '" +email+ "' and p.unique_id = '"+unique_id+"' ;")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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' ; ")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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.close()
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)+" ; ")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results else None
###################
def get_users_email_data(self,email):
with engine.connect() as conn:
stmt = text("select * from users where email = '"+email+"' ;")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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))
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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)+" ; ")
results = conn.execute(stmt).one_or_none()
return dict(results._mapping) if results 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 ; ")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
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 ; ")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
# def getDataForDay(self):
# with engine.connect() as conn:
# stmt = text("select program_day, hall,session_date,session_time from video_table where is_active >0 group by program_day order by program_day asc; ")
# results = conn.execute(stmt).all()
# return [dict(r._mapping) for r in results] if results else None
def getDataForDay(self):
with engine.connect() as conn:
stmt = text("select program_day, hall,session_date, year(session_date) as year ,session_time from video_table where is_active >0 group by year(session_date),program_day order by year(session_date),program_day asc; ")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
#SELECT * from video_table where program_day =1 and is_active >0 ;
def getDataByDay(self,program_day,year):
with engine.connect() as conn:
stmt = text("SELECT *,year(session_date) as year from video_table where program_day = "+str(program_day)+" and is_active >0 and year(session_date) = "+str(year)+" order by hall asc ; ")
results = conn.execute(stmt)
return [dict(r._mapping) for r in results] if results else None
def get_video_linkByVideoIdAndDay(self,video_id,program_day,year):
with engine.connect() as conn:
stmt = text("select * ,(select ifnull(min(video_id),0) from video_table where program_day = "+str(program_day)+" and year(session_date) ="+ str(year) +" and is_active = 1) as min_video_id,(select ifnull(max(video_id), 0) from video_table where program_day = "+str(program_day)+" and year(session_date) ="+ str(year) +" 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 year(session_date) ="+ str(year) +" 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 year(session_date) ="+ str(year) +" 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 year(session_date) ="+ str(year) +" and is_active = 1 order by order_by asc ; ")
print(stmt,"---------------")
results = conn.execute(stmt).all()
return [dict(r._mapping) for r in results] if results else None
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; ")
results = conn.execute(stmt).all()
return [dict(r) for r in results] if results else None
app.jinja_env.globals.update(UserModel=UserModel)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists