Sindbad~EG File Manager
from flask import request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,json,render_template_string,Response
from core.model.BadgeModel import BadgeModel
from core.model.LocalModel import LocalModel
from core.model.HallLogsModel import HallLogsModel
from core.library.email import EMAIL
from .. import Cryptography,Helper,server_url
# from flask import session, app
from random import randint
import datetime
from datetime import timedelta,date,datetime,time
# import requests, json
from werkzeug.utils import secure_filename
from os.path import join, dirname, realpath
import os
import flask
import string
import boto3, botocore
import webbrowser
import re
from flask import Flask
# from Code128 import Code128
# from base64 import b64encode
from collections import defaultdict
import math
from core import app
import requests
import base64
from urllib.parse import unquote
import pytz
UTC = pytz.utc
IST = pytz.timezone('Asia/Calcutta')
datetime_ist = datetime.now(IST)
# from flask_qrcode import QRcode
app = Blueprint('local', __name__)
@app.route('/get_sync', methods = ["GET","POST"])
def GetSync():
url = "http://127.0.0.1:5014/test_sync"
# url = "https://mobile-api.numerotech.com/menu_table?society_id=18&conf_id=27"
payload = {}
headers = {
'Cookie': 'session=585743aa-a675-4d65-96bf-d26908fde2af'
}
response = requests.request("GET", url, headers=headers, data=payload)
return response.text
@app.route('/<int:conf_id>/<conf_key>/post_sync_hall_data', methods = ["GET"])
def PostSyncHallData(conf_id,conf_key):
hall_id = request.values.get('hall_id')
pin_number = request.values.get('pin_number')
pin_number_bytes = pin_number.encode("ascii")
base64_bytes = base64.b64encode(pin_number_bytes)
pin_number_string = base64_bytes.decode("ascii")
now = datetime.now()
days = now.strftime('%d')
scan_table_name = f"{conf_key}_{int(days)}_{hall_id}_hall_scan"
url = server_url + "post_sync_table_data?hall_id="+str(hall_id)+"&conf_id="+str(conf_id)+"&conf_key="+conf_key+"&scan_table_name="+scan_table_name+""
last_update_sessions_local = LocalModel().get_last_update_session_local(conf_id,hall_id)
print("last_update_sessions_local -----",last_update_sessions_local)
hall_table_data = LocalModel().get_not_sync_hall_scan_data(conf_id, conf_key, hall_id,scan_table_name)
last_sync_at_local_result = LocalModel().get_last_sync_at_local(scan_table_name)
print("last_sync_at_local_result -- ",last_sync_at_local_result)
last_sync_at_local = None
if last_sync_at_local_result:
last_sync_at_local = last_sync_at_local_result.get("last_sync_at_local")
data = {
'last_update_sessions_local':last_update_sessions_local,
'hall_table_data_not_sync':hall_table_data,
'last_sync_at_local': last_sync_at_local
}
# return jsonify(data)
payload = json.dumps(data,default=str)
# return hall_table_data
# payload = {}
headers = {'Content-Type': 'application/json'}
response = requests.request("POST", url, headers=headers, data=payload)
# print("response.text - ",response.text)
data = json.loads(response.text)
last_sync_at = data["last_sync_at"]
msg = data["msg"]
scan_data_to_local = data["scan_data_to_local"]
active_session_live = data["active_session_live"]
print("active_session_live",active_session_live)
session_updated_at_live = None
asession_id_live = None
is_active_live = None
if active_session_live and active_session_live.get("updated_at"):
session_updated_at_live = datetime.strptime(active_session_live.get("updated_at"), "%a, %d %b %Y %H:%M:%S %Z") if active_session_live.get("updated_at") is not None else None
asession_id_live = active_session_live.get("asession_id")
is_active_live = active_session_live.get("is_active") or 0
if last_sync_at:
last_sync_at = datetime.strptime(last_sync_at, '%Y-%m-%d %H:%M:%S')
if msg =="success":
LocalModel().update_last_sync_at_from_live(last_sync_at,scan_table_name)
if scan_data_to_local:
LocalModel().insert_update_table_data_to_local(scan_data_to_local,scan_table_name,last_sync_at_local)
if session_updated_at_live and last_update_sessions_local.get('updated_at') == None:
LocalModel().update_active_session(asession_id_live,is_active_live,conf_id,hall_id,session_updated_at_live)
elif session_updated_at_live and session_updated_at_live > last_update_sessions_local.get('updated_at'):
LocalModel().update_active_session(asession_id_live,is_active_live,conf_id,hall_id,session_updated_at_live)
if (is_active_live == 0) or asession_id_live != last_update_sessions_local.get('asession_id'):
HallLogsModel().usp_generate_scan_logs_as_closed(conf_id,hall_id)
flash("Data sync to live Successfully" , "successMsg")
else:
flash(msg , "errorMsg")
return redirect(url_for('halllogs.HallScan',conf_id=conf_id,conf_key=conf_key ,pin_number=pin_number ))
# else:
# flash("data not exists" , "errorMsg")
# return redirect(url_for('halllogs.ScanLogs',conf_id=conf_id,conf_key=conf_key ,pin=pin_number_string ))
# # return "data not exist"
# # return "http://127.0.0.1:5014/"+str(conf_id)+"/"+conf_key+"/scan_logs?pin="+pin_number
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists