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
from .. import engine
import sqlite3
import pandas as pd
engine_sqlite = create_engine('sqlite:///sqlite_database.db')
class Society():
def __init__(self):
try:
self.meta = MetaData()
self.societies = Table("societies", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def getSocietybyId(self,society_id):
with engine.connect() as conn:
stmt = text("select * from societies where society_id = :society_id")
result = conn.execute(stmt.bindparams(society_id=society_id)).first()
conn.close()
if result :
return dict(result._mapping)
else:
return None
def getSociety(self,society_id,society_key):
with engine.connect() as conn:
stmt = text("select * from m_app_type mat "+
" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
" inner join societies s on s.society_id=sa.society_id"+
" inner join mail_setting ms on ms.mail_setting_id=sa.mail_setting_id where mat.app_type_id=1 and s.society_id=:society_id and s.society_key=:society_key;")
result = conn.execute(stmt.bindparams(society_id=society_id,society_key=society_key)).first()
conn.close()
if result :
return dict(result._mapping)
else:
return None
def setSociety(self,app_host):
with engine_sqlite.connect() as conn:
stmt = text("select * from m_app_type mat "+
" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
" inner join societies s on s.society_id=sa.society_id "+
" inner join mail_setting ms on ms.mail_setting_id=sa.mail_setting_id where mat.app_type_id=1 and sa.app_host=:app_host;")
result = conn.execute(stmt.bindparams(app_host=app_host)).first()
conn.close()
if result :
return dict(result._mapping)
else:
return None
def society_application(self,society_id):
with engine.connect() as conn:
stmt = text("select * from society_applications where society_id=:society_id and app_type_id=1;")
result = conn.execute(stmt.bindparams(society_id=society_id)).one_or_none()
conn.close()
if result :
return dict(result._mapping)
else:
return None
def getAllSociety(self):
with engine.connect() as conn:
stmt = text("select * from m_app_type mat "+
" inner join society_applications sa on sa.app_type_id=mat.app_type_id"+
" inner join societies s on s.society_id=sa.society_id where mat.app_type_id=1 and sa.is_daily_report_mail=1;")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def get_emails_data(self):
with engine.connect() as conn:
stmt = text("select group_concat(t.society_id)as society_id ,group_concat(s.society_key) as society_key,t.full_name,t.email,t.mobile from trigger_daily_reports_mails t inner join societies s on find_in_set(s.society_id,t.society_id) where t.is_mem =1 and t.is_active =1 group by t.full_name order by s.society_id asc")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def session_data_InsertToSqlite_1(self):
sqlite_conn = sqlite3.connect('sqlite_database.db')
tables = ['societies', 'm_app_type', 'society_applications', 'mail_setting']
for table in tables:
mysql_query = f"SELECT * FROM {table}"
df = pd.read_sql(mysql_query, engine)
df.to_sql(table, sqlite_conn, if_exists='replace', index=False)
sqlite_conn.commit()
engine.dispose()
sqlite_conn.close()
return "success"
def update_mem_tarrif(self,amount):
with engine.connect() as conn:
stmt = text("update society_map_member_type set amount=:amount where society_id=10 and member_type_id in (1,20,17);")
result = conn.execute(stmt.bindparams(amount=amount))
conn.commit()
conn.close()
return result
def get_update_mem_tarrif(self,now):
with engine.connect() as conn:
stmt = text(f"select s.society_id as schedule_society_id , s.member_type_id as schedule_member_type_id , s.scheduled_on,s.amount, t.society_id,t.member_type_id from schedule_member_tarrif s inner join society_map_member_type t on t.member_type_id = s.member_type_id and t.society_id = s.society_id where DATE_FORMAT(s.scheduled_on, '%Y-%m-%d %H:%i') = '{now}'")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
return results
def update_schedule_mem_tarrif(self,now,member_type_id):
with engine.connect() as conn:
stmt = text("update schedule_member_tarrif s inner join society_map_member_type t on t.member_type_id = s.member_type_id and t.society_id = s.society_id set s.prev_amount = t.amount, t.amount = s.amount ,updated_at= '"+str(now)+"' where DATE_FORMAT(s.scheduled_on, '%Y-%m-%d %H:%i') = '"+str(now)+"' and t.member_type_id = '"+str(member_type_id)+"';")
print(stmt)
result = conn.execute(stmt)
conn.commit()
return "success"
def get_all_data(self,now):
with engine.connect() as conn:
stmt = text(f"select s.society_id as schedule_society_id , s.member_type_id as schedule_member_type_id , s.scheduled_on,s.amount, s.prev_amount, t.society_id,t.member_type_id, mm.member_type,ss.society_name from schedule_member_tarrif s inner join m_member_type mm inner join society_map_member_type t on mm.member_type_id=t.member_type_id inner join societies ss on ss.society_id=t.society_id on t.member_type_id = s.member_type_id and t.society_id = s.society_id where t.updated_at='"+now+"';")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists