changes related to conversion
This commit is contained in:
parent
2d6857dd3f
commit
3ab7d8efcc
|
@ -34,11 +34,36 @@ from Blockchain2.block_user_info import user_info
|
|||
from lpp.certificate.createCertificate import certificateGenrate
|
||||
from django.conf import settings
|
||||
from MNF.settings import BasePath
|
||||
from Blockchain2.models import MNFServersFile
|
||||
from django.core.files import File as File2
|
||||
|
||||
|
||||
basePath = BasePath()
|
||||
|
||||
"""Converts a screenplay file"""
|
||||
def enforce_required_csv_structure(csv_path):
|
||||
required_columns = ["para_no", "scene_no", "content", "script_element"]
|
||||
|
||||
try:
|
||||
df = pd.read_csv(csv_path)
|
||||
except Exception as e:
|
||||
print(f"Error reading CSV: {e}")
|
||||
return
|
||||
|
||||
# Create a new DataFrame with required columns only
|
||||
new_df = pd.DataFrame()
|
||||
|
||||
for col in required_columns:
|
||||
if col in df.columns:
|
||||
new_df[col] = df[col]
|
||||
else:
|
||||
new_df[col] = ""
|
||||
|
||||
try:
|
||||
new_df.to_csv(csv_path, index=False)
|
||||
print("CSV updated successfully with only required columns.")
|
||||
except Exception as e:
|
||||
print(f"Error writing CSV: {e}")
|
||||
|
||||
class Conversion:
|
||||
|
||||
|
@ -123,28 +148,39 @@ class Conversion:
|
|||
except Exception as e:
|
||||
print("Error of Audit is:", e)
|
||||
status.status = "FAILURE"
|
||||
status.error_msg = "AIAUDITinProgress"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB2'
|
||||
|
||||
print(
|
||||
"Script Audit failed due to some internal error."
|
||||
" If you have made any payment for conversion "
|
||||
"that will be refunded")
|
||||
|
||||
to = self.user.email
|
||||
key_value = {
|
||||
"User": self.user.username,
|
||||
}
|
||||
sendmail(to_email=[to], email_code="PP21", key_value=key_value)
|
||||
# auto refund code
|
||||
try:
|
||||
auto_refund(self.translated_script_object.central_payment_id)
|
||||
new_docx_script , unique_script_languages, unique_dialogue_languages = audit.audit_ai_script()
|
||||
status.status = States.SUCCESS
|
||||
status.error_msg = "AIAUDIT-Complete"
|
||||
status.save()
|
||||
print("Audit AI Script is done")
|
||||
except Exception as e:
|
||||
print("No Refund -> ", e)
|
||||
return self.response
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB2'
|
||||
|
||||
print(
|
||||
"Script Audit failed due to some internal error."
|
||||
" If you have made any payment for conversion "
|
||||
"that will be refunded")
|
||||
|
||||
to = self.user.email
|
||||
key_value = {
|
||||
"User": self.user.username,
|
||||
}
|
||||
sendmail(to_email=[to], email_code="PP21", key_value=key_value)
|
||||
# auto refund code
|
||||
try:
|
||||
auto_refund(self.translated_script_object.central_payment_id)
|
||||
except Exception as e:
|
||||
print("No Refund -> ", e)
|
||||
return self.response
|
||||
print("AUDITING IS DONE")
|
||||
file_path_ = filesystem.get_file_path(audit_id, "script-csv")
|
||||
print("file_path_ -> ", file_path_)
|
||||
enforce_required_csv_structure(file_path_)
|
||||
script_data = MNFScriptDatabase.objects.get(script_id=self.original_script_object.script_id)
|
||||
script_data.audit_id = str(audit_id)
|
||||
script_data.save()
|
||||
|
@ -304,12 +340,26 @@ class Conversion:
|
|||
print("blockchain script conversion 3", uploaded_script, translated_scripttt)
|
||||
with open(uploaded_script, 'rb') as f:
|
||||
hash = uploadDataToIPFSNode(f)
|
||||
django_file = File2(f)
|
||||
filename = os.path.basename(uploaded_script)
|
||||
files, _ = MNFServersFile.objects.get_or_create(
|
||||
project_id= obj.translation_id,
|
||||
file_type="original_scriptFile_hash",
|
||||
)
|
||||
files.public_file.save(filename, django_file)
|
||||
scriptconversion["original_scriptFile_hash"] = hash
|
||||
scriptconversion["original_scriptFile_path"] = uploaded_script
|
||||
scriptconversion["date_at"] = current_datetime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print("blockchain script conversion 4")
|
||||
with open(translated_scripttt, 'rb') as f1:
|
||||
hash = uploadDataToIPFSNode(f1)
|
||||
django_file = File2(f1)
|
||||
filename = os.path.basename(translated_scripttt)
|
||||
files, _ = MNFServersFile.objects.get_or_create(
|
||||
project_id= obj.translation_id,
|
||||
file_type="translated_scriptFile_hash",
|
||||
)
|
||||
files.public_file.save(filename, django_file)
|
||||
scriptconversion["translated_scriptFile_hash"] = hash
|
||||
scriptconversion["translated_scriptFile_path"] = translated_scripttt
|
||||
print("blockchain script conversion 5")
|
||||
|
@ -347,6 +397,13 @@ class Conversion:
|
|||
# script_size = file_to_audit_docx.file.size
|
||||
with open(script_path1, 'rb') as _file:
|
||||
hash2 = uploadDataToIPFSNode(_file)
|
||||
django_file = File2(_file)
|
||||
filename = os.path.basename(script_path1)
|
||||
files, _ = MNFServersFile.objects.get_or_create(
|
||||
project_id= obj.translation_id,
|
||||
file_type="script-json",
|
||||
)
|
||||
files.public_file.save(filename, django_file)
|
||||
print(f"## hash2 ----> {hash2}")
|
||||
script_json["script_file_path"] = script_path1
|
||||
script_json["script_file"] = hash2
|
||||
|
@ -362,35 +419,36 @@ class Conversion:
|
|||
Data = str(scriptconversion)
|
||||
userPrivateKey = blockchain_obj.privateKey
|
||||
userkey = decryptionOfPrivate(userPrivateKey)
|
||||
tx_id, tx_gas_fee = UploadConversionData(OWNER_KEY, blockchain_obj.publicKey, UserId, str(Project),
|
||||
Data)
|
||||
if obj.User_preference !="MNF":
|
||||
tx_id, tx_gas_fee = UploadConversionData(OWNER_KEY, blockchain_obj.publicKey, UserId, str(Project),
|
||||
Data)
|
||||
|
||||
print("Tx id -> ", tx_id,tx_gas_fee)
|
||||
print(type(tx_id))
|
||||
print("Tx id -> ", tx_id,tx_gas_fee)
|
||||
print(type(tx_id))
|
||||
|
||||
|
||||
try:
|
||||
user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=tx_gas_fee,
|
||||
script_name=self.name_script)
|
||||
addition_result = user_infos.update_info(self)
|
||||
print("Blockchain Result -> ",addition_result)
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
try:
|
||||
user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=tx_gas_fee,
|
||||
script_name=self.name_script)
|
||||
addition_result = user_infos.update_info(self)
|
||||
print("Blockchain Result -> ",addition_result)
|
||||
except Exception as e:
|
||||
print("Error:", e)
|
||||
|
||||
print("blockchain script conversion 6")
|
||||
# certificatepath = certificateGenrate(self.user.username, "script conversion", hash)
|
||||
certificatepath = certificateGenrate(self.user.username, "script conversion", hash, projectname=self.name_script, matic = tx_gas_fee)
|
||||
hash = hash_decrypation(hash)
|
||||
to_email = [self.user.email]
|
||||
email_code = 'BL1'
|
||||
print("blockchain script conversion 6")
|
||||
# certificatepath = certificateGenrate(self.user.username, "script conversion", hash)
|
||||
certificatepath = certificateGenrate(self.user.username, "script conversion", hash, projectname=self.name_script, matic = tx_gas_fee)
|
||||
hash = hash_decrypation(hash)
|
||||
to_email = [self.user.email]
|
||||
email_code = 'BL1'
|
||||
|
||||
key_value = {
|
||||
"Product Name": "script conversion",
|
||||
"Profile url": f"{settings.SITE_DOMAIN}/memberpage/#/personaldetails",
|
||||
"User url": f"{settings.SITE_DOMAIN}/memberpage/#/user/{self.user.id}/personaldetails",
|
||||
"Product output card url": f"{settings.SITE_DOMAIN}/conversion/view_conversion/",
|
||||
}
|
||||
sendmail(to_email=to_email, email_code=email_code,key_value=key_value, filePath=certificatepath)
|
||||
key_value = {
|
||||
"Product Name": "script conversion",
|
||||
"Profile url": f"{settings.SITE_DOMAIN}/memberpage/#/personaldetails",
|
||||
"User url": f"{settings.SITE_DOMAIN}/memberpage/#/user/{self.user.id}/personaldetails",
|
||||
"Product output card url": f"{settings.SITE_DOMAIN}/conversion/view_conversion/",
|
||||
}
|
||||
sendmail(to_email=to_email, email_code=email_code,key_value=key_value, filePath=certificatepath)
|
||||
except Exception as e:
|
||||
self.translated_script_object.error_desc = "Error in blockchain is " + str(e)
|
||||
self.translated_script_object.save()
|
||||
|
|
Loading…
Reference in New Issue