Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, null, select,update,delete,text
from sqlalchemy.sql import and_, or_
from sqlalchemy import asc, desc
from core import app
import json
#engine = create_engine(app.config['DATABASE_URI'])
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class CMEScanModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def delegateDataForCMEScan(self,conf_id,del_table_name,signup_for_alldays,signup_table,curr_date):
with engine.connect() as conn:
conn = engine.connect()
if signup_for_alldays > 0 :
stmt = text("select d.delegate_id, d.delegate_no,d.role,d.full_name,d.email,d.mobile,d.city,d.state,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conf_id from "+del_table_name+" d "
+" left join "+ signup_table +" s on s.delegate_no = d.delegate_no and d.conf_id = s.conf_id and s.signin_date= '"+curr_date+"' "
+ " where d.conf_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('VOLUNTEER','TRADE','EXHIBIOR','CREW','SUPPORT - IT','SUPPORT - AV') group by d.delegate_no order by d.delegate_no asc;")
print("if block")
else :
stmt = text("select d.delegate_id, d.delegate_no,d.role,d.full_name,d.email,d.mobile,d.city,d.state,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conf_id from "+del_table_name+" d "
+" left join "+ signup_table +" s on s.delegate_no = d.delegate_no and d.conf_id = s.conf_id "
+ " where d.conf_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('VOLUNTEER','TRADE','EXHIBIOR','CREW','SUPPORT - IT','SUPPORT - AV') group by d.delegate_no order by d.delegate_no asc;")
'''
stmt = text("select delegate_id,delegate_no,role,full_name,email,mobile,city,state,membership_no,mc_number, counter,batch,signed_by,comments,signed_on,updated_at,conf_id from "+del_table_name+" where conf_id = "+str(conf_id)+
" and delegate_no > 0 and delegate_no is not null and role not in ('VOLUNTEER','TRADE','EXHIBIOR','CREW','SUPPORT - IT','SUPPORT - AV');")
'''
stmt_2 = text(" SET sql_mode ='' ;")
conn.execute(stmt_2)
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
def usp_search_regdesk_v1(self,del_table_name,search_data,is_delegate,conf_id,signup_table,signup_for_alldays,curr_date):
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_search_regdesk_v1",[del_table_name,search_data,is_delegate,conf_id,signup_table,signup_for_alldays,curr_date])
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 updateAndGetSignedCount(self,conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("update_android_sync_data",[conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table])
while 1:
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def syncAllDataWithSignedCount(self,conf_id,del_table_name,date_1,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
#call usp_android_sync_with_signed_count(1, 'delegates_demo','2023-03-07',1,'numerotech_primary_db_conf.signup_demo');
# signup_for_alldays,signup_table,curr_date
cursor.callproc("usp_android_sync_with_signed_count",[conf_id,del_table_name,date_1,signup_for_alldays,signup_table])
while 1:
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def getDelegateDataCMEScan(self,conference_id,delegate_no):
with engine.connect() as conn:
stmt = text("select * from delegates where conference_id ="+str(conference_id)+" and delegate_no ="+str(delegate_no)+" limit 1;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
def get_mcstates_of_india(self,country_id):
with engine.connect() as conn:
stmt = text("select country_id,state_id,state_name from states where country_id = "+str(country_id)+" order by state_name asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
def updateDelegatedata_cme(self,del_table_name,prefix,full_name,email,mobile,mc_state_id,mc_number,delegate_no,conf_id):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("usp_update_delegatedata_from_cmescan",[del_table_name,prefix,full_name,email,mobile,mc_state_id,mc_number,delegate_no,conf_id])
while 1:
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def count_email(self,user_id,email,society_id):
with engine.connect() as conn:
stmt = text("select count(*) as count from users where user_id <> "+str(user_id)+" and email= '"+email+"' and society_id="+str(society_id)+";")
results = conn.execute(stmt).one_or_none()
if results :
return dict(results._mapping)
else:
return None
def update_member(self,user_id,datas):
with engine.connect() as conn:
try:
stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(datas)
result = conn.execute(stmt)
conn.commit()
return result
except Exception as e:
return str(e)
def update_badge_scan_signup(self,conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("update_badge_scan_signup",[conf_id,delegate_no,del_table_name,curr_dt,signed_by,comments,curr_date,signup_for_alldays,signup_table])
while 1:
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def getCMEScandelegateRecord(self,conf_id,del_table_name,signup_table,conf_date):
with engine_conf.connect() as conn:
if conf_date and "All" in conf_date :
stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.state,d.membership_no,d.role,d.mc_number,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+del_table_name+" d inner join "+signup_table+" s on d.conf_id = s.conf_id and d.delegate_no = s.delegate_no ;")
else :
stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.state,d.membership_no,d.role,d.mc_number,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+del_table_name+" d inner join "+signup_table+" s on d.conf_id = s.conf_id and d.delegate_no = s.delegate_no where s.signin_date = '"+conf_date+"' ;")
print (stmt)
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
return results
def getCMEScanybydelegaateno(self,conf_id,signup_table,delegate_no):
with engine_conf.connect() as conn:
stmt = text("select signin_date,signed_on from "+signup_table+" where conf_id = "+str(conf_id)+" and delegate_no = "+delegate_no+";")
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists