conversion lpp s3 output file saving

This commit is contained in:
Ubuntu 2024-04-30 12:29:42 +00:00
parent 5288f6ba1b
commit 37654cb4ec
1 changed files with 90 additions and 65 deletions

View File

@ -466,70 +466,6 @@ class Conversion:
"""Blockchain Upload Starts here"""
# sys.stdout = original_stdout
scriptconversion = {}
try:
print("trying blockchain 1")
current_datetime = datetime.datetime.now()
if UserCredentialsForBlockchain.objects.filter(user=self.user).exists():
obj = self.translated_script_object
obj2 = self.original_script_object
temp1 = str(obj2.script)
temp2 = str(obj.translated_script_path)
uploaded_script = f"{basePath}/media/{temp1}"
translated_scripttt = f"{basePath}{temp2}"
print("blockchain script conversion 3", uploaded_script, translated_scripttt)
with open(uploaded_script, 'rb') as f:
hash = uploadDataToIPFSNode(f)
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)
scriptconversion["translated_scriptFile_hash"] = hash
scriptconversion["translated_scriptFile_path"] = translated_scripttt
print("blockchain script conversion 5")
blockchain_obj = UserCredentialsForBlockchain.objects.get(user=self.user)
UserId = blockchain_obj.user_id
Project = obj.translation_id
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)
print("Tx id -> ", tx_id,tx_gas_fee)
# user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=2345432345123456)
# addition_result = user_infos.update_info(request)
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)
hash = hash_decrypation(hash)
to_email = [self.user.email]
email_code = 'BL1'
key_value = {
"service": "script conversion",
"hash": hash,
"public key": blockchain_obj.publicKey,
"private key": userkey.decode('utf-8'),
"Transaction Hash": tx_id
}
sendmail(to_email=to_email, email_code=email_code, key_value=key_value, filePath=certificatepath)
except Exception as e:
print("Error in blockchain is", e)
"""Blockchain Upload Ends here"""
"""Translation Completion mail here""" """Translation Completion mail here"""
to = self.user.email to = self.user.email
@ -557,7 +493,96 @@ class Conversion:
X.save() X.save()
task_assigner(int(X.task_id), "conversion") task_assigner(int(X.task_id), "conversion")
"""Vetting Process Done"""
# adding file to s3 output folder
object_name = "OUTPUT/" + (self.translated_script_object.translated_script_path.split("/"))[-1]
filee = basePath + self.translated_script_object.translated_script_path
# Upload the file
import os
import boto3
bucket = "conversion-kitchen"
s3_client = boto3.client('s3',
aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
aws_secret_access_key="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",
region_name="ap-south-1"
)
try:
response = s3_client.upload_file(filee, bucket, object_name)
s3_url = f"https://{bucket}.s3.ap-south-1.amazonaws.com/{object_name}"
self.translated_script_object.translated_script_pdf = s3_url
print(response)
except Exception as e:
print("Error is", e)
else:
"""Blockchain Upload Starts here"""
# sys.stdout = original_stdout
scriptconversion = {}
try:
print("trying blockchain 1")
current_datetime = datetime.datetime.now()
if UserCredentialsForBlockchain.objects.filter(user=self.user).exists():
obj = self.translated_script_object
obj2 = self.original_script_object
temp1 = str(obj2.script)
temp2 = str(obj.translated_script_path)
uploaded_script = f"{basePath}/media/{temp1}"
translated_scripttt = f"{basePath}{temp2}"
print("blockchain script conversion 3", uploaded_script, translated_scripttt)
with open(uploaded_script, 'rb') as f:
hash = uploadDataToIPFSNode(f)
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)
scriptconversion["translated_scriptFile_hash"] = hash
scriptconversion["translated_scriptFile_path"] = translated_scripttt
print("blockchain script conversion 5")
blockchain_obj = UserCredentialsForBlockchain.objects.get(user=self.user)
UserId = blockchain_obj.user_id
Project = obj.translation_id
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)
print("Tx id -> ", tx_id,tx_gas_fee)
# user_infos = user_info(tx_hash=tx_id, service="Conversion", gas_fee=2345432345123456)
# addition_result = user_infos.update_info(request)
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)
hash = hash_decrypation(hash)
to_email = [self.user.email]
email_code = 'BL1'
key_value = {
"service": "script conversion",
"hash": hash,
"public key": blockchain_obj.publicKey,
"private key": userkey.decode('utf-8'),
"Transaction Hash": tx_id
}
sendmail(to_email=to_email, email_code=email_code, key_value=key_value, filePath=certificatepath)
except Exception as e:
print("Error in blockchain is", e)
"""Blockchain Upload Ends here"""
"""Process Completed""" """Process Completed"""
self.translated_script_object.status = "Completed" self.translated_script_object.status = "Completed"