Sindbad~EG File Manager
from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_
from core import app
engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600,future=True)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_pre_ping=True,pool_recycle=3600,future=True)
class QueryModel():
def __init__(self):
try:
self.meta = MetaData()
# self.abs_session_queries = Table("abs_session_queries",self.meta,autoload = True, autoload_with= engine)
except Exception as e:
print(e)
def getConf_open_closedForQuery(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+"' <= 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 checkDelegateNo(self,conf_id,delegate_no,del_table_name):
with engine.connect() as conn:
stmt = text("select * from "+del_table_name+" where conf_id =:conf_id and delegate_no =:delegate_no limit 1;")
results = conn.execute(stmt.bindparams(conf_id=conf_id,delegate_no=delegate_no)).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def insert_delegate_query(self,insert_stmt):
with engine_conf.connect() as conn:
try:
stmt = text(insert_stmt)
results = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
conn.commit()
return str(e)
# result = conn.execute(self.abs_session_queries.insert(), data)
# conn.close()
# pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
# return pk_id
def getDaysQueryModel(self,abs_session_table,conf_id) :
with engine.connect() as conn:
stmt = text ("SELECT distinct(display_dt),dt from "+str(abs_session_table)+" where conf_id=:conf_id order by dt asc")
results = conn.execute(stmt.bindparams(conf_id=conf_id)).all()
return [dict(r._mapping) for r in results] if results else None
def getDaysQueryModelByDate(self,abs_session_table,conf_id,conf_date) :
with engine.connect() as conn:
stmt = text ("SELECT distinct(display_dt),dt from "+str(abs_session_table)+" where conf_id=:conf_id and dt=:conf_date order by hall;")
result = conn.execute(stmt.bindparams(conf_id=conf_id,conf_date=conf_date)).first()
return dict(result._mapping) if result else None
def getHallsQueryModel(self,abs_session_table,conf_id,conf_date) :
with engine.connect() as conn:
stmt = text ("SELECT distinct(hall),hall_id,dt,display_dt from "+str(abs_session_table)+" where conf_id=:conf_id and dt=:conf_date order by hall;")
results = conn.execute(stmt.bindparams(conf_id=conf_id,conf_date=conf_date)).all()
return [dict(r._mapping) for r in results] if results else None
def getSessionNameQuery(self,abs_session_table,conf_id,hall_id,conf_date) :
with engine.connect() as conn:
stmt = text ("SELECT * from "+str(abs_session_table)+" where conf_id=:conf_id and hall_id=:hall_id and dt=:conf_date order by starts_by asc")
results = conn.execute(stmt.bindparams(conf_id=conf_id,hall_id=hall_id,conf_date=conf_date))
return [dict(r._mapping) for r in results] if results else None
def get_sessionQueryModel(self,abs_session_table,conf_id,asession_id):
with engine.connect() as conn:
stmt = text("select * from "+str(abs_session_table)+" where conf_id=:conf_id and asession_id=:asession_id;")
results = conn.execute(stmt.bindparams(conf_id=conf_id,asession_id=asession_id))
results= results.one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getCurrentSessionQueryModel(self,abs_session_table,conf_id,current_dt,hall_id,conf_date):
with engine.connect() as conn:
stmt = text("select * from "+str(abs_session_table)+" where conf_id =:conf_id and hall_id=:hall_id and dt=:conf_date and '"+current_dt+"' between starts_by and ends_by ;")
results = conn.execute(stmt.bindparams(conf_id=conf_id,hall_id=hall_id,conf_date=conf_date))
results= results.one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getQueries(self,abs_session_queries_table,asession_id,conf_date):
with engine.connect() as conn:
stmt = text("select * from "+str(abs_session_queries_table)+" where asession_id=:asession_id and date(created_at)=:conf_date order by created_at desc limit 1;")
results = conn.execute(stmt.bindparams(asession_id=asession_id,conf_date=conf_date)).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def getAutoQueriesModel(self,abs_session_queries_table,asession_id,last_sync_at):
with engine.connect() as conn:
stmt = text("select * from "+str(abs_session_queries_table)+" where asession_id=:asession_id and created_at >:last_sync_at order by created_at desc;")
results = conn.execute(stmt.bindparams(asession_id=asession_id,last_sync_at=last_sync_at)).all()
return [dict(r._mapping) for r in results] if results else None
def usp_get_pre_nxt_query_model(self,asession_id):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_pre_nxt_query",[asession_id])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
finally:
# Return the connection to the pool (won't actually close).
connection.commit()
connection.close()
return sets
def usp_get_session_query_model(self,conf_id,hall_id,conf_date,current_dt):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_session_query",[conf_id,hall_id,conf_date,current_dt])
while 1:
#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
finally:
# Return the connection to the pool (won't actually close).
connection.commit()
connection.close()
return sets
def usp_generate_query_session(self,db_name,abs_sessions_table,conf_id):
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_generate_query_session",[db_name,abs_sessions_table,conf_id])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def update_abs_sessions(self,table_name,session_date,session_day,conf_id):
with engine_conf.connect() as conn:
stmt = text("update "+str(table_name)+" set display_dt = '{}' where dt = '{}' and conf_id={}".format(session_day,session_date,conf_id))
result = conn.execute(stmt)
conn.commit()
if result:
return "success"
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists