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_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class LocationScanModel():
def __init__(self):
try:
self.meta = MetaData()
except Exception as e:
print(e)
def insert_location_scan_data(self,conf_id,user_id,qr_id,created_at,created_date):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
cursor.callproc("save_location_scan_data",[conf_id,user_id,qr_id,created_at,created_date])
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 get_scan_user(self,conf_id,user_id):
conn = engine_conf.connect()
where_con = " "
base_stmt = "select qg.qr_id,qg.location,qg.is_visible,lsl.created_date,lsl.created_at,u.prefix,u.user_id,u.gender,u.full_name,u.email,u.mobile from numerotech_primary_db_conf.qr_generate qg inner join numerotech_primary_db_conf.location_scan_logs lsl on qg.qr_id = lsl.qr_id inner join numerotech_primary_db.users u on u.user_id = lsl.user_id inner join numerotech_primary_db.conference c on c.society_id = u.society_id where c.conf_id = "+str(conf_id) + " "
if user_id :
where_con = " and lsl.user_id = "+str(user_id)
sql_1 = base_stmt+where_con
stmt = text(sql_1)
result=conn.execute(stmt)
results = [dict(r) for r in result] if result else None
conn.close()
if results :
return results
else:
return None
def getLocationScanCount(self,conf_id,user_id):
conn = engine_conf.connect()
stmt = text("select count( user_id) as user_scan_count from location_scan_logs where conf_id = "+str(conf_id)+" and user_id = "+str(user_id)+" ;")
result=conn.execute(stmt)
results = [dict(r) for r in result] if result else None
conn.close()
if results :
return results[0]
else:
return None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists