Sindbad~EG File Manager

Current Path : /home/numerotech/whatsapp.numerotech.com/whatsapp/core/library/
Upload File :
Current File : //home/numerotech/whatsapp.numerotech.com/whatsapp/core/library/helper.py

from core import app
from flask import url_for,render_template_string
from datetime import datetime, date, time, timedelta
import random
# import datetime
from num2words import num2words
from core.library.auth import Auth
import base64
from jinja2 import Environment, FileSystemLoader
import requests
from os.path import splitext
from urllib.parse import urlparse
from decimal import Decimal
# from datetime import datetime
#settime working as global variable but commented for easy identification of this variable using class name 
# global settime
# settime = 5

class Helper:

	# PaymentGatewayAppMasterID = 7 # IAGES23 razorpay
	# PaymentGatewayISTest      = 1 # testmode = 1

	DefaultCountryID          = 101 # for india country code
	AppType                   = "DELEGATE"
	from_photo_upload_dt      = {54:'2024-07-16',39:'2024-07-16',52:'2024-08-23',48:'2024-08-23',57:'2024-08-23',53:'2024-08-23',69:'2024-08-29',50:'2024-08-23'}
	
	def test_login(data):
		return "Virtual Conference - 1" 
	
	def footer_text():
		return "Virtual Conference - 1" 
	
	
	def date_diff(d1, d2):
		# fmt   = '%H:%M'
		d1      =   date(d1,'%Y, %m, %d')
		d2      =   date(d2,'%Y, %m, %d')           
		diff    =   str(d1) - str(d2)       
		# print(diff)
		return diff


	
	def random4digt():
		number = random.randint(1000,9999)
		return number

	def amountTowords(amount):
		words_in_amount = num2words(amount, lang='en_IN')
		return words_in_amount  

	def amountTodecimal(amount):
		num = int(amount)
		rs = f"{num:,}"
		return rs   



	def getcurrenttimestamp():
		ct = datetime.now()
		ts = ct.timestamp()
		return ts 	



	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 formatINR(number):
		s, *d = str(number).partition(".")
		r = ",".join([s[x-2:x] for x in range(-3, -len(s), -2)][::-1] + [s[-3:]])
		return "".join([r] + d)
	
	def convert_html(data):
		temp = app.jinja_env.from_string("{{login_content|safe}}").render(**data)
		return render_template_string(temp,**data)

	def convert_html_for_payment_screen(payment_content,amount,show_paynow_btn):
		temp = app.jinja_env.from_string("{{payment_content.payment_content|safe}}").render(payment_content=payment_content,amount=amount,show_paynow_btn=show_paynow_btn)
		return render_template_string(temp,payment_content=payment_content,amount=amount,show_paynow_btn=show_paynow_btn)


	def split_delegate_ids(delegate_ids):
		if delegate_ids:
			delegate_id = delegate_ids.split(',')
			delegate_ids = len(delegate_id)
		else:
			delegate_ids = 0
			
		return delegate_ids
		
		
	def base64encode(value):
		value          = str(value)
		basevalue      = value.encode("ascii")
		base64_bytes   = base64.b64encode(basevalue)
		return base64_bytes.decode("ascii")
		
	def base64decode(value):
		try:
			enc_user_id     = value
			base64_bytes    = enc_user_id.encode("ascii")
			sample_bytes    = base64.b64decode(base64_bytes) 
			return sample_bytes.decode("ascii")
		except:
			return ""


	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):
		# print("in helper>>>>>>>>>>",data)
		temp = app.jinja_env.from_string("{{mail_content|safe}}").render(**data)
		return render_template_string(temp,**data)
		
	def convert_special_char(data):
		bad_chars      = ['"',"'","!","@","#","$","%","^","&","*","(",")","+","}","|","{",":","?",">","<","/","=","[","]"]
		sheet_name     = ''.join(j for j in str(data) if not j in bad_chars)
		sheet_name     = str(sheet_name)
		return str(sheet_name)
		
	def convert_jinja_to_html(html_content,session_user):
		temp = app.jinja_env.from_string(html_content).render(session_user=session_user)
		return render_template_string(temp,**session_user)	
	
	def concat_for_url(text,values):
		text = text+values
		return text
		
	def calculate_age(birthdate):
		birthdate = str(birthdate)
		birthdate = datetime.strptime(birthdate, '%Y-%m-%d')
		today = datetime.today()
		age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
		return age
		
	def ImageDecodeBase64(url):
		if url:
			bytes_string =  base64.b64encode(requests.get(url).content)
			aa = str(bytes_string, 'utf-8')
			return aa
		else :
			return " "	

	def GetExtensionFileUrl(url):
		if url:
			path = urlparse(url).path
			ext = splitext(path)[1]
			return ext
		else:
			return ''	
	
	def to_float(value):
		print("-------1-------------",value)
		if isinstance(value, Decimal):
			print("----------2----------",value)
			return float(value)

		return value

app.jinja_env.globals.update(Helper=Helper) 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists