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
import json
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_fk = create_engine(app.config['DATABASE_URI_FK'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class KitSessionModel():
def __init__(self):
try:
self.meta = MetaData()
self.kc_sessions = Table("kc_sessions", self.meta, autoload_with=engine_fk)
self.kc_users = Table("kc_users", self.meta, autoload_with=engine_fk)
except Exception as e:
print(e)
def getkcConf(self,conf_id,conf_key,current_dt):
with engine.connect() as conn:
# stmt =text("select * from conference where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' and '"+current_dt+"' between conf_start_time and conf_end_time ;")
stmt =text("select * from conference where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"' ;")
results = conn.execute(stmt).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getKcConfData(self,conf_id,conf_key):
with engine.connect() as conn:
stmt =text("select * from conference where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"';")
results = conn.execute(stmt).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getDataByuser_name(self,user_name):
with engine_fk.connect() as conn:
conn = engine_fk.connect()
stmt = text("select * from kc_users where user_name = '"+user_name+"' ;")
results = conn.execute(stmt).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getSessionData(self,conf_id,conf_key):
with engine_fk.connect() as conn:
stmt_2 = text("SELECT k.session_id,k.session_name,k.session_key,k.start_time,k.end_time, k.is_active from kc_sessions k where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"';")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def insert_kitdata_and_getdata(self,data,conf_id,conf_key):
with engine_fk.connect() as conn:
result = conn.execute(self.kc_sessions.insert(), data)
conn.commit()
stmt_2 = text("SELECT k.session_id,k.session_name,k.session_key,k.start_time,k.end_time,k.is_active from kc_sessions k where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"';")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def edit_kitbo(self,session_id):
with engine_fk.connect() as conn:
stmt = select([self.kc_sessions]).where(self.kc_sessions.c.session_id.in_([session_id]))
results = conn.execute(stmt).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def update_kitbo_and_getdata(self,data_for_update,session_id,conf_id,conf_key):
with engine_fk.connect() as conn:
stmt = self.kc_sessions.update().where(self.kc_sessions.c.session_id.in_([session_id])).values(data_for_update)
restult_1 = conn.execute(stmt)
conn.commit()
stmt_2 = text("SELECT k.session_id,k.session_name,k.session_key,k.start_time,k.end_time, k.is_active from kc_sessions k where conf_id ="+str(conf_id)+" and conf_key ='"+conf_key+"';")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def delete_kit_session_index(self,session_id):
with engine_fk.connect() as conn:
stmt = self.kc_sessions.delete().where(self.kc_sessions.c.session_id.in_([session_id]))
restult_1 = conn.execute(stmt)
conn.commit()
stmt_2 = text("SELECT k.session_id,k.session_name,k.session_key,k.start_time,k.end_time from kc_sessions k ;")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def updateKITLoginTime(self,kc_user_id,current_dt) :
with engine_fk.connect() as conn:
stmt = text("UPDATE kc_users set login_at = '"+current_dt+"' where kc_user_id = " + str(kc_user_id) + " ;")
# stmt = self.kc_users.update().where(self.kc_users.c.kc_user_id.in_([kc_user_id])).values({'login_at' : current_dt})
results = conn.execute(stmt)
conn.commit()
if results :
return "success"
else:
return "failure"
def getKcsessionData(self,conf_id,conf_key) :
with engine_fk.connect() as conn:
stmt = text("select * from kc_sessions where conf_id ="+str(conf_id)+" and conf_key = '"+conf_key+"';")
result = conn.execute(stmt).one_or_none()
if result :
return dict(result._mapping)
else :
return None
def insert_kit_session(self,session_insert_stmt):
with engine_fk.connect() as conn:
stmt = text(session_insert_stmt)
result = conn.execute(stmt)
conn.commit()
return result
def edit_kcbo(self,conf_id,session_id):
with engine_fk.connect() as conn:
stmt = text("select * from kc_sessions where conf_id = "+str(conf_id)+" and session_id = "+session_id+" ;")
result = conn.execute(stmt)
result = result.fetchone()
return dict(result._mapping) if result else None
def delete_kitbodata_and_getdata(self,conf_id,session_id):
with engine_fk.connect() as conn:
# stmt_1 = text("update kc_sessions set deleted_at = '"+current_dt+"' where conf_id = "+str(conf_id)+" and session_id= "+str(session_id)+";")
stmt_1 = text("delete from kc_sessions where conf_id = "+str(conf_id)+" and session_id= "+str(session_id)+";")
result = conn.execute(stmt_1)
conn.commit()
stmt = text("select * from kc_sessions where conf_id = "+str(conf_id)+" ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists