Sindbad~EG File Manager

Current Path : /home/numerotech/hs.numerotech.com/scan_v1/core/model/
Upload File :
Current File : //home/numerotech/hs.numerotech.com/scan_v1/core/model/HallLogsModel.py

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_fk   = create_engine(app.config['DATABASE_URI_FK'],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 HallLogsModel():
	def __init__(self):
		try:
			self.meta       = MetaData()
			self.scan_logs  = Table("scan_logs", self.meta, autoload_with=engine_conf)
		   
		except Exception as e:
			print(e)

	def GetConf(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+"'  limit 1;")
			result = conn.execute(stmt)
			result = result.first()
			conn.close()
			return dict(result._mapping) if result else None		
			
	def gethall(self,conf_id,pin_number):
		with engine.connect() as conn:
			# stmt = text("select * from halls where conf_id =:conf_id and (entry_pin_number =:pin_number or exit_pin_number =:pin_number) and is_active = 1 ;")
			stmt = text("select * from halls where conf_id ="+str(conf_id)+" and (pin_number ="+str(pin_number)+") and is_active = 1 ;")
			print(stmt)
			result = conn.execute(stmt)
			result = result.first()
			conn.close()
			return dict(result._mapping) if result else None


	def usp_save_hall_scanned_data_by_day(self,conf_id,delegate_no,hall_id,del_table_name):
		connection  = engine_conf.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_save_hall_scanned_data_by_day",[conf_id,delegate_no,hall_id,del_table_name])

		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()
			connection.close()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			connection.close()
			return None

			
	def usp_generate_session_table_scan_logs(self,conf_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_conf_generate_session_table_scan_logs_by_day",[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()
			connection.close()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.close()



	def gethall_name(self,conf_id):
		with engine_conf.connect() as conn:
			stmt  = text("select * from halls where conf_id = "+str(conf_id)+" order by  order_no asc;")
			print(stmt)
			# stmt  = text("select * from "+scan_table_name+" where  entry_at is not null and exist_at is null;")	
			result  = conn.execute(stmt).all()
			conn.close()
			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