Sindbad~EG File Manager
from flask import request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,json,render_template_string,Response
from firebase_admin import messaging,exceptions
from core.model.NotificationModel import NotificationModel
import firebase_admin
from firebase_admin import auth,credentials
from .. import Cryptography,Auth,RouteGroup,path_wkhtmltopdf,is_windows_os
from dateutil.rrule import rrule, DAILY
from datetime import timedelta,date,datetime,time
import os,sys
from flask import make_response
from os.path import join, dirname, realpath
import ast
app = Blueprint('notification', __name__)
# Author : vimal
# Created on : 23-Jan-2024 10:00 AM
# Usage : firebase Push notificate for mobile app
# @app.route('<int:conf_id>/<conf_key>/cron_job_commitments',methods=["POST","GET"])
@app.route('<int:conf_id>/<conf_key>/agenta_schedule_fb_notification',methods=["POST","GET"])
@RouteGroup.conf_required
@RouteGroup.login_required #check if login else automatically redirect to login page
@RouteGroup.bo_access_required
def CronJobCommitment(conf_id,conf_key):
conf_data = Auth.get_conference(conf_id)
start_date = conf_data['conf_start_dt']
end_date = conf_data['conf_end_dt']
confe_date = []
if start_date and end_date:
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
confe_date.append(dt.strftime("%Y-%m-%d"))
user_id=None
date=None
time=None
# conf_ids=17
get_user_comm=NotificationModel().GetUserCommitment(user_id,date,time,conf_id)
test_user=NotificationModel().GetTestCommitmentUsers(conf_id)
return render_template('/backoffice/abstract/notification/notification_cmt.html',conf_id=conf_id,conf_key=conf_key,confe_date=confe_date,get_user_comm=get_user_comm,test_user=test_user)
@app.route('<int:conf_id>/<conf_key>/get_date_time_notification_data',methods=["POST","GET"])
@RouteGroup.conf_required
@RouteGroup.login_required #check if login else automatically redirect to login page
@RouteGroup.bo_access_required
def GetDateTimeNotification_data(conf_id,conf_key):
user_id=None
date=request.values.get('date_commit') or None
# date='2023-08-04'
time=request.values.get('start_date') or None
get_user_comm=NotificationModel().GetUserCommitment(user_id,date,time,conf_id)
html_data=render_template('/backoffice/abstract/notification/notification_cmt_table.html',conf_id=conf_id,conf_key=conf_key,get_user_comm=get_user_comm)
data = {"html_data" :html_data,"msg" : "success" ,"status" : 1 }
json_data = json.dumps(data,default = str)
return json_data
@app.route('<int:conf_id>/<conf_key>/send_fbn',methods =["GET","POST"])
def SendFBN(conf_id,conf_key):
failure_count = 0
conf_name = Auth.get_conference(conf_id).get('conf_name')
if not firebase_admin._apps:
FIRBASE_PATH = "core/static/firebase_config"
filename = "boa-mobileapp-firebase-adminsdk.json"
json_file = os.path.join(FIRBASE_PATH, filename)
cred = credentials.Certificate(json_file)
firebase_admin.initialize_app(cred)
image = None
user_id=None
now = datetime.now()
curr_dt = now.strftime("%Y-%m-%d %H:%M:%S")
# date = now.strftime("%Y-%m-%d")
# time=now.strftime("%H:%M:%S")
time=request.values.get('time') or None
if time==None:
time=now.strftime("%H:%M")
date=request.values.get('date') or None
if (date==None or date=='None'):
date = now.strftime("%Y-%m-%d")
token=request.values.get('fcm_token') or None
get_user_comm=NotificationModel().GetUserCommitment(user_id,date,time,conf_id)
users_cmd = []
for i in get_user_comm:
device_type=i["device_type"]
fb_user_id=i["fb_user_id"]
if token==None:
fcm_token=i['fcm_token']
else:
fcm_token=token
notification_content=i['message']
notification_title=conf_name +' - Agenta Notification'
# vimal
# fcm_token = 'cp01DH2pS06rzTHtnEiKdR:APA91bHzyvBVqTEFjubcPAijjHWgzLQI8aIElM25MZU_iSRyb97lICITmGGXppP2tBIPM0kj52abSD_F-w1s4lVbm9WwPUc1Yw9rP4Li39bi8tRQ_68zOIsUeKnAp4VUfCDJbQzzCnHK'
# sri sir
# fcm_token='eqe9bcUGGEKJsP5ABcsX63:APA91bFLG4X2pW4vGArymGKPGlfbLjdShkt8a-8GjtXYs2SesuwjW4GsxEiIK6dXjkyspAPEO0U2TIxBEx1T-yxHkuhoosOKYR-DwAzpDtYoref6Incz_gSfrd-dSCh-qOTC9aafMVmL'
# print(fcm_token)
if image :
user["image"] = image
message = messaging.Message(
notification=messaging.Notification(
title=notification_title,
body=notification_content,
image =image,
),
token=fcm_token
)
else :
message = messaging.Message(
notification=messaging.Notification(
title=notification_title,
body=notification_content,
),
token=fcm_token
)
try:
response = messaging.send(message)
# response = "Success"
suc_msg = "Successfully sent message: " + response
except messaging.UnregisteredError:
failure_count = failure_count +1
suc_msg = 'Error: Registration token is no longer valid'
except Exception as e:
print('Error:', str(e))
data={
'notification_title':notification_title,
'notification_content':notification_content,
'created_at':curr_dt,
'updated_at':curr_dt,
'conf_id':conf_id,
'fcm_token':fcm_token,
'fb_user_id':fb_user_id,
'device_type':device_type,
'fb_message':suc_msg
}
users_cmd.append(data)
get_data = NotificationModel().saveNotificationLogsMysql(conf_id,users_cmd)
data = {"msg" : "success" ,"status" : 1 }
json_data = json.dumps(data,default = str)
return json_data
# return redirect(url_for('notification.CronJobCommitment',conf_id=conf_id,conf_key=conf_key))
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists