Sindbad~EG File Manager
from core import app
from flask import render_template_string
from flask import url_for
from datetime import datetime, date, time, timedelta
import datetime
import imp,sys
import base64
import pyqrcode
import io
import png
import barcode
from PIL import Image, ImageOps, ImageChops
#settime working as global variable but commented for easy identification of this variable using class name
# global settime
# settime = 5
class Helper:
Institution = ['ksos23']
def_cat_id = 161
mark1 = 10
mark2 = 10
mark3 = 10
test_mail = "mukeshkumar@numerotec.com"
testmail = "mukeshkumar@numerotec.com"
master_email_ids = ["mukeshkumar@numerotec.com","manjula@numerotec.com","priyavarthana@numerotec.com","drchaitra@hotmail.com","info@kosonline.org"]
CC_Presentation_type_id = 23
cdn_url = "https://cdn.jsdelivr.net/gh/NumeroTec/ntec_cdn@main"
defaultParams = {
'Paper' : 'Content (25),Presentation (25),Slides (25),Originality (25)',
'Poster' : 'Content (25),Presentation (25),Slides (25),Originality (25)',
'Video' : 'Presentation (25),Originality (25),Scientific Content (25),Cinematic Content (25)'
}
def isAjax(request):
if request.headers.get("X-Requested-With") == "XMLHttpRequest":
return True
else:
return False
def convert_jinja_template_v1(data1,data):
# data1 = data1[0]
temp = app.jinja_env.from_string(data1["template_data"]).render(data=data)
return render_template_string(temp)
def convert_jinja_template(data1,data):
data1 = data1[0]
temp = app.jinja_env.from_string(data1["template_data"]).render(data=data)
return render_template_string(temp)
def footer_text():
return ""
def email_mask(email):
if email:
lo = email.find('@')
if lo>0:
mask_email = email[0]+"*****"+email[lo-1:]
return mask_email
return email
def mobile_mask(mobile):
if mobile:
lo = len(mobile)
if lo>0:
mask = mobile[:2]+"******"+mobile[lo-2:]
return mask
return mobile
def call_custom_controller(abs_type,conf_key):
module_name = abs_type+"Controller"
fp, pathname, description = imp.find_module(module_name,["./core/controller/"+conf_key.upper()])
module = imp.load_module(module_name, fp, pathname, description)
myclass = getattr(module, module_name)
return myclass
def merge_tags(text,values):
for k, v in values.items():
text = text.replace('*|'+k+'|*', v)
return text
def convert_html_for_mail_screen(data):
temp = app.jinja_env.from_string("{{mail_content|safe}}").render(**data)
return render_template_string(temp,**data)
def getcurrenttimestamp():
ct = datetime.datetime.now()
ts = ct.timestamp()
return ts
def calculate_age(born):
today = date.today()
return today.year - born.year - ((today.month, today.day) < (born.month, born.day))
def get_role_data(absData):
chiefins = None
coins = []
chiefauthor = None
presauthor = None
coauthor = []
others = []
for item in absData['topics']:
if item['role_id'] == 32:
chiefins = item
if item['role_id'] == 33:
coins.append(item)
if item['role_id'] == 34:
chiefauthor = item
if item['role_id'] == 35:
presauthor = item
if item['role_id'] == 36:
coauthor.append(item)
if item['role_id'] not in (32,33,34,35,36):
others.append(item)
return chiefins,coins,chiefauthor,presauthor,coauthor,others
def convert_comma_to_dict(data):
output = dict(item.split("=") for item in data.split(","))
return output
def convert_html_for_mail_screen_v1(data,get_abs_type,get_reminder_attachment,conf_id,conf_key):
temp = app.jinja_env.from_string(data).render(get_abs_type=get_abs_type,get_reminder_attachment=get_reminder_attachment,conf_id=conf_id,conf_key=conf_key)
return render_template_string(temp)
def calcluate_age_v1(date1,date2,year1,year2,mon1,mon2,day1,day2):
Months = {
1:31, 2:28, 3:31, 4:30, 5:31, 6:30, 7:31,
8:31, 9:30, 10:31, 11:30, 12:31
}
# Differnce between two dates/Total no. of days
TotalDays = (date2 - date1).days
# print(date1.year)
# If birth year and current year are the same
if int(year1) == int(year2):
month = TotalDays/30
day = TotalDays%30
year = 0
else:
year = TotalDays/365
month = (TotalDays%365)/30
# Check if the given year is a leap year or not.
# If Yes, then Make the total number of days
# in the month of February 29.
if Helper.is_leap_year(int(year2)):
Months[2] = 29
if int(day2) >= int(day1):
day = int(day2) - int(day1)
# If the current month is February and the
# current year is a leap year or not
elif int(mon2) == 2 and (Helper.is_leap_year(int(year2)) or (not Helper.is_leap_year(int(year2)))):
year = year
month = 11
# Check if the current month is January or Not
if int(mon2) == 1:
prevMonth = Months[int(mon2)]
else:
prevMonth = Months[int(mon2)-1]
days = prevMonth - int(day1) + int(day2)
day = days
else:
if int(mon2) == 1:
prevMonth = Months[int(mon2)]
else:
prevMonth = Months[int(mon2)-1]
days = prevMonth - int(day1) + int(day2)
day = days
month = month
# Printing the result
# print(" Age is: ",int(year),"years ", int(month), "months ", int(day), "days")
age = f"""<lable class='h5'><b> Age is </b></label> {int(year)} years {int(month)} months {int(day)} days"""
# print(age)
# age = " Age is: " int(year) "years "
return age
def is_leap_year(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False
def getQRCodeWithBg(delegate_no,color_code):
c = pyqrcode.create(delegate_no)
s = io.BytesIO()
# c.png(s,scale=6) dcf2fb a2b2da
if color_code:
c.png(s,scale=6, background=color_code)
else:
c.png(s,scale=6)
# Customize options for the barcode
options = {
'write_text': False, # Hide the text below the barcode
'module_height': 8, # Set the height of each module (barcode line)
'module_width': 0.3, # Set the width of each module (barcode line)
}
# Open the generated barcode image from BytesIO using Pillow
barcode_image = Image.open(s)
# Convert the image to RGBA mode (if not already in RGBA)
barcode_image = barcode_image.convert("RGBA")
# Create a mask for the white background
background = Image.new("RGBA", barcode_image.size, (0, 0, 0, 0))
diff = ImageChops.difference(barcode_image, background)
diff = ImageOps.invert(diff.convert('L'))
# Make the white background transparent
barcode_image.putalpha(diff)
# Save the barcode image to BytesIO
output = io.BytesIO()
barcode_image.save(output, format='PNG')
# Encode the image as base64
encoded_image = base64.b64encode(output.getvalue()).decode("ascii")
return encoded_image
def getQRCodeForCustom(qr_val):
result = ''
img_src = None
if qr_val:
qr_val = "tel:"+qr_val
result = f"data:image/png;base64,{Helper.getQRCodeWithBg(qr_val,'#fff')}"
return result
app.jinja_env.globals.update(Helper=Helper)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists