audit removed after translation
This commit is contained in:
parent
ba265ca0fb
commit
32a58b114b
|
@ -59,14 +59,7 @@ class Conversion:
|
|||
self.response = {}
|
||||
|
||||
print("Conversion Process Initializing")
|
||||
# original_stdout = sys.stdout
|
||||
|
||||
"""Initializing Variables"""
|
||||
# script_id = request.session["script_id"]
|
||||
# original_script = MNFScriptDatabase.objects.get(script_id=script_id)
|
||||
# translated_script = ScriptTranslations.objects.get(translation_id=request.session.get("translation_id", None))
|
||||
|
||||
# Getting all choices of user regarding Full Dialogues Translation
|
||||
self.full_dialogue_option_choices = [True if value.strip() == "True" else False for value in
|
||||
str(self.translated_script_object.full_dialogue_option_choices).split(",")]
|
||||
|
||||
|
@ -81,41 +74,14 @@ class Conversion:
|
|||
self.name_script = (str(((self.original_script_object.script.name).split("/"))[-1]).split("."))[0]
|
||||
self.file_extension = (str(self.original_script_object.script.name).split("."))[-1]
|
||||
|
||||
# Dual dialogue
|
||||
# if dual_dialogue_option := request.POST.get('dual_dialogue_option') == "on":
|
||||
|
||||
# dual_left_language = request.POST.get('dual_left_language')
|
||||
# dual_left_script = request.POST.get('dual_left_script')
|
||||
|
||||
# # lpp vetting
|
||||
# if lpp_vetting := request.POST.get('lpp_vetting') == "on":
|
||||
|
||||
# lpp_vetting_type = request.POST.get('radioGroup')
|
||||
|
||||
# if lpp_vetting_type == "radioOption1":
|
||||
|
||||
# pass
|
||||
|
||||
# elif lpp_vetting_type == "radioOption1":
|
||||
|
||||
# pass
|
||||
|
||||
def convert(self):
|
||||
"""Audit Code starts here"""
|
||||
|
||||
print("Conversion Auditing is starting")
|
||||
original_stdout = sys.stdout
|
||||
# x = MNFScriptDatabase.objects.get(script_id=request.POST['script_id'])
|
||||
# scripttt = basePath + "/media/" + original_script.script.name
|
||||
# exten = (str(self.original_script_object.script.name).split("."))[-1]
|
||||
# name_script = str(((((scripttt).split("/"))[-1]).split("."))[0])
|
||||
print("name of script", self.name_script)
|
||||
print("sample script", self.sample_id)
|
||||
print("existing_script", self.existing_script)
|
||||
|
||||
"""if file is not a sample script and not a existing script then only audit it"""
|
||||
if not self.existing_script and not self.original_script_object.sample_script:
|
||||
print("----Auditing----")
|
||||
|
||||
|
||||
script1 = str(self.file_path)
|
||||
doc = open(script1, 'rb').read()
|
||||
file = ContentFile(
|
||||
|
@ -153,19 +119,19 @@ class Conversion:
|
|||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB1'
|
||||
#sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
|
||||
except Exception as e:
|
||||
print("Error of Audit is:", e)
|
||||
status.status = "FAILURE"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB2'
|
||||
#sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
|
||||
print(
|
||||
"Script Audit failed due to some internal error."
|
||||
" If you have made any payment for conversion "
|
||||
"that will be refunded")
|
||||
# email for failure
|
||||
|
||||
to = self.user.email
|
||||
key_value = {
|
||||
"User": self.user.username,
|
||||
|
@ -182,202 +148,17 @@ class Conversion:
|
|||
script_data = MNFScriptDatabase.objects.get(script_id=self.original_script_object.script_id)
|
||||
script_data.audit_id = str(audit_id)
|
||||
script_data.save()
|
||||
# to_email = [self.user.email]
|
||||
# email_code = 'SB1'
|
||||
#sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
|
||||
|
||||
try:
|
||||
df = pd.read_csv(file_path_, encoding="utf-8")
|
||||
except UnicodeError:
|
||||
df = pd.read_csv(file_path_, encoding="utf-16")
|
||||
pd.set_option('display.max_rows', None)
|
||||
pd.set_option('display.max_columns', None)
|
||||
|
||||
|
||||
self.list_of_lists = df.values.tolist()
|
||||
print("Audit Done")
|
||||
|
||||
|
||||
|
||||
elif self.original_script_object.sample_script:
|
||||
sample_script = SampleScript.objects.get(sample_id=self.original_script_object.sample_id.sample_id)
|
||||
if sample_script.audit_id:
|
||||
audit_id = sample_script.audit_id
|
||||
file_path_ = filesystem.get_file_path(audit_id, "script-csv")
|
||||
try:
|
||||
df = pd.read_csv(file_path_, encoding="utf-8")
|
||||
except UnicodeError:
|
||||
df = pd.read_csv(file_path_, encoding="utf-16")
|
||||
pd.set_option('display.max_rows', None)
|
||||
pd.set_option('display.max_columns', None)
|
||||
self.list_of_lists = df.values.tolist()
|
||||
else:
|
||||
print("----Auditing----")
|
||||
script1 = str(self.file_path)
|
||||
doc = open(script1, 'rb').read()
|
||||
file = ContentFile(
|
||||
doc,
|
||||
(script1.split("/"))[-1],
|
||||
)
|
||||
language_code = "en"
|
||||
result = filesystem.new_screenplay_without_audit_in_background(
|
||||
self.audit_user,
|
||||
self.audit_user.username,
|
||||
str(self.name_script),
|
||||
file,
|
||||
"script-original",
|
||||
language_code,
|
||||
)
|
||||
audit_id = result.get("script", {}).get("id")
|
||||
ScriptAuditModel.objects.update_or_create(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
),
|
||||
defaults={"status": States.STARTED}
|
||||
)
|
||||
audit = NeutralAudit(audit_id, False)
|
||||
status = ScriptAuditModel.objects.get(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
)
|
||||
)
|
||||
try:
|
||||
if self.file_extension == "fdx":
|
||||
audit.audit_fdx()
|
||||
else:
|
||||
audit.audit()
|
||||
status.status = "SUCCESS"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB1'
|
||||
#sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
except:
|
||||
status.status = "FAILURE"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB2'
|
||||
#sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
print(
|
||||
"Script Audit failed due to some internal error."
|
||||
" If you have made any payment for conversion "
|
||||
"that will be refunded")
|
||||
# email for failure
|
||||
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
|
||||
file_path_ = filesystem.get_file_path(
|
||||
audit_id, "script-csv")
|
||||
sample_script.audit_id = str(audit_id)
|
||||
sample_script.save()
|
||||
try:
|
||||
df = pd.read_csv(file_path_, encoding="utf-8")
|
||||
except UnicodeError:
|
||||
df = pd.read_csv(file_path_, encoding="utf-16")
|
||||
pd.set_option('display.max_rows', None)
|
||||
pd.set_option('display.max_columns', None)
|
||||
dataframe = df
|
||||
self.list_of_lists = dataframe.values.tolist()
|
||||
|
||||
|
||||
elif self.existing_script:
|
||||
falser = False
|
||||
if falser:
|
||||
# if MNFScriptDatabase.objects.get(script_id=self.original_script_object.script_id).audit_id:
|
||||
audit_id = MNFScriptDatabase.objects.get(script_id=self.original_script_object.script_id).audit_id
|
||||
file_path_ = filesystem.get_file_path(audit_id, "script-csv")
|
||||
try:
|
||||
df = pd.read_csv(file_path_, encoding="utf-8")
|
||||
except UnicodeError:
|
||||
df = pd.read_csv(file_path_, encoding="utf-16")
|
||||
pd.set_option('display.max_rows', None)
|
||||
pd.set_option('display.max_columns', None)
|
||||
dataframe = df
|
||||
self.list_of_lists = dataframe.values.tolist()
|
||||
else:
|
||||
print("----Auditing----")
|
||||
script1 = str(self.file_path)
|
||||
doc = open(script1, 'rb').read()
|
||||
file = ContentFile(
|
||||
doc,
|
||||
(script1.split("/"))[-1],
|
||||
)
|
||||
language_code = "en"
|
||||
unique_str = "_" + str(int(time.time()))
|
||||
result = filesystem.new_screenplay_without_audit_in_background(
|
||||
self.audit_user,
|
||||
self.audit_user.username,
|
||||
str(self.name_script)+str(unique_str),
|
||||
file,
|
||||
"script-original",
|
||||
language_code,
|
||||
)
|
||||
audit_id = result.get("script", {}).get("id")
|
||||
ScriptAuditModel.objects.update_or_create(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
),
|
||||
defaults={"status": States.STARTED}
|
||||
)
|
||||
audit = NeutralAudit(audit_id, False)
|
||||
status = ScriptAuditModel.objects.get(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
)
|
||||
)
|
||||
try:
|
||||
if self.file_extension == "fdx":
|
||||
audit.audit_fdx()
|
||||
else:
|
||||
audit.audit()
|
||||
status.status = "SUCCESS"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB1'
|
||||
sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
except:
|
||||
status.status = "FAILURE"
|
||||
status.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB2'
|
||||
sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
print(
|
||||
"Script Audit failed due to some internal error."
|
||||
" If you have made any payment for conversion "
|
||||
"that will be refunded")
|
||||
# email for failure
|
||||
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
|
||||
file_path_ = filesystem.get_file_path(
|
||||
audit_id, "script-csv")
|
||||
script_data = MNFScriptDatabase.objects.get(script_id=self.original_script_object.script_id)
|
||||
script_data.audit_id = str(audit_id)
|
||||
script_data.save()
|
||||
to_email = [self.user.email]
|
||||
email_code = 'SB1'
|
||||
sendmail(to_email=to_email, email_code=email_code,key_value={"script_name":self.name_script})
|
||||
try:
|
||||
df = pd.read_csv(file_path_, encoding="utf-8")
|
||||
except UnicodeError:
|
||||
df = pd.read_csv(file_path_, encoding="utf-16")
|
||||
pd.set_option('display.max_rows', None)
|
||||
pd.set_option('display.max_columns', None)
|
||||
dataframe = df
|
||||
self.list_of_lists = dataframe.values.tolist()
|
||||
|
||||
sys.stdout = original_stdout
|
||||
print("Audit Done")
|
||||
self.translated_script_object.status = "Audited"
|
||||
|
@ -389,6 +170,11 @@ class Conversion:
|
|||
dataframe = self.list_of_lists
|
||||
|
||||
args = [self.full_dialogue_option_choices, self.sentence_dialogue_option_choices, self.other_option_choices]
|
||||
print("printing args")
|
||||
print("args[0] - full_dialogue_option_choices:", args[0])
|
||||
print("args[1] - sentence_dialogue_option_choices:", args[1])
|
||||
print("args[2] - other_option_choices:", args[2])
|
||||
|
||||
|
||||
kwargs = {
|
||||
"user": self.translated_script_object.user_id,
|
||||
|
@ -403,10 +189,16 @@ class Conversion:
|
|||
"dial_dest_lang": self.translated_script_object.dial_dest_language,
|
||||
"dial_dest_script": self.translated_script_object.dial_dest_script,
|
||||
"translation_id": self.translated_script_object.translation_id,
|
||||
"script_id": self.original_script_object.script_id
|
||||
"script_id": self.original_script_object.script_id,
|
||||
"csv_path":file_path_,
|
||||
"audit_id": audit_id,
|
||||
}
|
||||
|
||||
# original_stdout = sys.stdout
|
||||
print("printing kwargs")
|
||||
for key, value in kwargs.items():
|
||||
print(f"{key}: {value}")
|
||||
|
||||
|
||||
|
||||
try:
|
||||
ScriptTranslation(*args, **kwargs)
|
||||
|
@ -441,66 +233,24 @@ class Conversion:
|
|||
self.translated_script_object = ScriptTranslations.objects.get(
|
||||
translation_id=self.translated_script_object.translation_id)
|
||||
|
||||
"""Juggernaut Payment Updation"""
|
||||
try:
|
||||
if self.juggernaut_pages_deduction:
|
||||
user_data = JuggernautPackage.objects.filter(user_id = self.user)
|
||||
if user_data.count() == 1:
|
||||
pass
|
||||
else:
|
||||
self.session = {}
|
||||
try:
|
||||
if user_data.count() > 1:
|
||||
max_beat = 0
|
||||
for i in user_data:
|
||||
if i.conversion_pages >= max_beat:
|
||||
user_data = i
|
||||
self.session['user_data'] = str(user_data.id)
|
||||
except Exception as e:
|
||||
print("Juggernaut error is",e)
|
||||
max_beat = 0
|
||||
|
||||
self.session['user_data'] = str(user_data.id)
|
||||
update_juggernaut(self,
|
||||
user_id=self.user.id,
|
||||
service_name="conversion",
|
||||
conversion_pages=self.juggernaut_pages_deduction,
|
||||
associated_project=self.original_script_object,
|
||||
translation_language=self.language_set)
|
||||
self.original_script_object = MNFScriptDatabase.objects.get(
|
||||
script_id=self.original_script_object.script_id)
|
||||
self.original_script_object.is_juggernaut_used = True
|
||||
# if script_original.languages_juggernaut != "":
|
||||
# # script_original.languages_juggernaut = str(script_original.languages_juggernaut) + "," + str(
|
||||
# # script_translated.dial_dest_language)
|
||||
# else:
|
||||
# script_original.languages_juggernaut = str(script_translated.dial_dest_language)
|
||||
self.original_script_object.save()
|
||||
except Exception as e:
|
||||
self.translated_script_object.error_desc = str(e)
|
||||
self.translated_script_object.save()
|
||||
print("Error in juggernaut updation is",e)
|
||||
"""Juggernaut Payment Updation Done"""
|
||||
|
||||
|
||||
|
||||
"""Translation Completion mail here"""
|
||||
if not self.translated_script_object.lpp:
|
||||
to = self.user.email
|
||||
key_value = {
|
||||
"User": self.user.username,
|
||||
"Title": self.original_script_object.script_title
|
||||
"Title": self.original_script_object.script_title,
|
||||
"translated language":self.translated_script_object.dial_dest_language,
|
||||
}
|
||||
sendmail(to_email=[to], email_code="PP18", key_value=key_value)
|
||||
|
||||
"""Translation Completion mail 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
|
||||
|
||||
bucket = "conversion-kitchen"
|
||||
s3_client = boto3.client('s3',
|
||||
|
@ -535,25 +285,6 @@ class Conversion:
|
|||
task_assigner(int(X.task_id), "conversion")
|
||||
|
||||
|
||||
# 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
|
||||
# bucket = "conversion-kitchen"
|
||||
# s3_client = boto3.client('s3',
|
||||
# aws_access_key_id="AKIAQVLBBGCB45RMLKVW",
|
||||
# aws_secret_access_key="ZWc6KOc5LuBLuCEBDDfQTor+Q7rp3fFH74gVt+AA",
|
||||
# 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}"
|
||||
|
||||
# print(response)
|
||||
# except Exception as e:
|
||||
# print("Error is", e)
|
||||
|
||||
|
||||
else:
|
||||
|
||||
|
@ -583,17 +314,25 @@ class Conversion:
|
|||
scriptconversion["translated_scriptFile_path"] = translated_scripttt
|
||||
print("blockchain script conversion 5")
|
||||
|
||||
if obj.converted_audit_id:
|
||||
# if obj.converted_audit_id:
|
||||
print("audit blockchain")
|
||||
print("blockchain script conversion 5.1")
|
||||
# blockchain upload of csv-json data
|
||||
try:
|
||||
adit_id = obj.converted_audit_id
|
||||
print(f"## aaaaaaaadit_id----> {adit_id}")
|
||||
except:
|
||||
print("audit id not found")
|
||||
print(f"## audit id ---> {audit_id}")
|
||||
|
||||
|
||||
file_to_audit = File.objects.get(
|
||||
script=adit_id,
|
||||
script=audit_id,
|
||||
type="script-csv"
|
||||
)
|
||||
|
||||
csv_script_path = file_to_audit.file.path
|
||||
print(f"## csv_script_path ----> {csv_script_path}")
|
||||
df = pd.read_csv(csv_script_path)
|
||||
df = df.loc[:, ["content", "script_element"]]
|
||||
script_json: dict = json.loads(utilities.csv_to_json(df))
|
||||
|
@ -608,11 +347,13 @@ class Conversion:
|
|||
# script_size = file_to_audit_docx.file.size
|
||||
with open(script_path1, 'rb') as _file:
|
||||
hash2 = uploadDataToIPFSNode(_file)
|
||||
print(f"## hash2 ----> {hash2}")
|
||||
script_json["script_file_path"] = script_path1
|
||||
script_json["script_file"] = hash2
|
||||
script_json["type"] = "script-json"
|
||||
script_json["screenplay_name"] = str(self.name_script)
|
||||
scriptconversion["script-json"] = script_json
|
||||
|
||||
print("blockchain script conversion 5.2")
|
||||
|
||||
blockchain_obj = UserCredentialsForBlockchain.objects.get(user=self.user)
|
||||
|
@ -627,8 +368,7 @@ class Conversion:
|
|||
print("Tx id -> ", tx_id,tx_gas_fee)
|
||||
print(type(tx_id))
|
||||
|
||||
# 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)
|
||||
|
@ -643,13 +383,7 @@ class Conversion:
|
|||
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
|
||||
# }
|
||||
|
||||
key_value = {
|
||||
"Product Name": "script conversion",
|
||||
"Profile url": f"{settings.SITE_DOMAIN}/memberpage/#/personaldetails",
|
||||
|
|
|
@ -12,6 +12,7 @@ from centralisedFileSystem.models import Script
|
|||
from django.core.files.base import ContentFile
|
||||
from scriptAudit.models import ScriptAuditModel, States
|
||||
from scriptAudit.mnf_script_audit import NeutralAudit
|
||||
import pandas as pd
|
||||
basePath = BasePath()
|
||||
|
||||
|
||||
|
@ -65,7 +66,7 @@ def ScriptTranslation(*args, **kwargs):
|
|||
translated_dataframe = copy.deepcopy(dataframe)
|
||||
|
||||
|
||||
for index, data in enumerate(translated_dataframe):
|
||||
for index, data in enumerate(dataframe):
|
||||
|
||||
if data[3] == 'action':
|
||||
|
||||
|
@ -379,16 +380,8 @@ def ScriptTranslation(*args, **kwargs):
|
|||
translated_dataframe[index][2] = makeTransliteration_only(**kwargs2)
|
||||
|
||||
|
||||
# here only transliteration will happen and not translation
|
||||
|
||||
elif data[3] == 'speaker':
|
||||
# if args[2][4]:
|
||||
#
|
||||
# translated_dataframe[index][2] = translate_comparison2(data[2], kwargs['non_dial_src_lang'],
|
||||
# kwargs['non_dial_dest_lang'])
|
||||
# line_language = kwargs['non_dial_dest_lang']
|
||||
# line_script = language_script(kwargs['non_dial_dest_lang'])
|
||||
#
|
||||
# else:
|
||||
line_language = kwargs['non_dial_src_lang']
|
||||
line_script = kwargs['non_dial_src_script']
|
||||
|
||||
|
@ -506,7 +499,9 @@ def ScriptTranslation(*args, **kwargs):
|
|||
kwargs['dial_dest_lang'], translation_instance.dual_dial_script)
|
||||
|
||||
# sample_title = original_script.script_title
|
||||
|
||||
df_translated = pd.DataFrame(translated_dataframe,columns=["para_no","scene_no","content","script_element"])
|
||||
csv_path = kwargs['csv_path']
|
||||
df_translated.to_csv(csv_path, index=False, encoding="utf-8")
|
||||
if original_script.sample_script:
|
||||
data = [kwargs['dial_src_lang'], kwargs['non_dial_src_lang'], kwargs['non_dial_dest_lang'],
|
||||
kwargs['dial_src_script'], kwargs['dial_dest_script'], kwargs['non_dial_src_script'],
|
||||
|
@ -526,118 +521,28 @@ def ScriptTranslation(*args, **kwargs):
|
|||
if (translation_instance != None):
|
||||
if original_script.sample_script:
|
||||
print(doc_file)
|
||||
# if dual_dial_script != "Yes":
|
||||
# converted_df = pd.DataFrame(converted_df,
|
||||
# columns=['dataframe', 'para_no', 'content', 'script_element'])
|
||||
# print("Translated and Transliterated DF is", converted_df)
|
||||
# converted_file = csv_to_docx(converted_df)
|
||||
|
||||
|
||||
converted_file.save(doc_file)
|
||||
print("convert to pdf called", "and it is inside sample script translations")
|
||||
# convert_to_pdf(doc_file, "/".join((doc_file.split("/"))[:-1]))
|
||||
# os.remove(doc_file)
|
||||
|
||||
saveFile = doc_file.split('.')[0] + ".pdf"
|
||||
translation_instance.translated_script_path = "/media/" + str(doc_file.split('media')[1])
|
||||
# translation_instance.translated_script_pdf = "/media/" + str(saveFile.split('media')[1])
|
||||
translation_instance.save()
|
||||
return saveFile
|
||||
|
||||
# if dual_dial_script != "Yes":
|
||||
# converted_df = pd.DataFrame(converted_df, columns=['dataframe', 'para_no', 'content', 'script_element'])
|
||||
# print("Translated and Transliterated DF is", converted_df)
|
||||
# converted_file = csv_to_docx(converted_df)
|
||||
|
||||
|
||||
converted_file.save(doc_file)
|
||||
# convert_to_pdf(doc_file, get_pdf_save_dir())
|
||||
saveFile = doc_file.split('.')[0] + ".pdf"
|
||||
translation_instance.translated_script_path = "/media/" + str(doc_file.split('media')[1])
|
||||
# translation_instance.translated_script_pdf = "/media/" + str(saveFile.split('media')[1])
|
||||
translation_instance.status = "Translated"
|
||||
translation_instance.converted_audit_id = kwargs['script_id']
|
||||
translation_instance.save()
|
||||
# return saveFile
|
||||
# print("saved done go to ")
|
||||
|
||||
original_stdout = sys.stdout
|
||||
"""code for saving translated df into script pad for editing"""
|
||||
if not original_script.sample_script:
|
||||
'''
|
||||
saving the converted df to script_csv of the centralised file System
|
||||
'''
|
||||
# audited_file_name = "audit_translated.docx"
|
||||
# converted_df2 = pd.DataFrame(converted_df,
|
||||
# columns=['dataframe', 'para_no', 'content', 'script_element'])
|
||||
# converted_df2.to_csv("/home/user/mnf/project/MNF/conversion/translation/translated/test_csv.csv")
|
||||
# audited_docx = csv_to_docx(converted_df2)
|
||||
# audited_
|
||||
# req_file = ContentFile(
|
||||
# doc_file,
|
||||
# (doc_file.split("/"))[-1],
|
||||
# )
|
||||
# try:
|
||||
# print("inside try of script_csv saving")
|
||||
# existing_file = File.objects.get(type="script-original", script_id=audited_id)
|
||||
# existing_file.file = req_file
|
||||
# existing_file.save()
|
||||
# print("script-csv saved in the models")
|
||||
# except Exception as exp:
|
||||
# print("Con-Aud Exception = ", exp)
|
||||
# print("this doesnt work much :(")
|
||||
# File.objects.update(
|
||||
# script=Script.objects.get(id=audited_id), # audied_id
|
||||
# type="script-csv",
|
||||
# file=req_file,
|
||||
# )
|
||||
# print("----> Script id from conv-aud is here=", audited_id).
|
||||
existing_script = kwargs["iteration_no"]
|
||||
if existing_script:
|
||||
audit_name = str(
|
||||
((doc_file.split("/"))[-1]).split(".")[0]) + f"_{kwargs['iteration_no']}"
|
||||
else:
|
||||
audit_name = str(((doc_file.split("/"))[-1]).split(".")[0])
|
||||
from utils import filesystem
|
||||
file = ContentFile(
|
||||
open(doc_file, 'rb').read(),
|
||||
(doc_file.split("/"))[-1],
|
||||
)
|
||||
language_code = "en"
|
||||
# result = filesystem.new_screenplay(
|
||||
# request.user,
|
||||
# request.user.username,
|
||||
# audit_name,
|
||||
# file,
|
||||
# "script-original",
|
||||
# language_code,
|
||||
# )
|
||||
result = filesystem.new_screenplay_without_audit_in_background(
|
||||
kwargs['user'],
|
||||
kwargs['user'].username,
|
||||
str(audit_name),
|
||||
file,
|
||||
"script-original",
|
||||
language_code,
|
||||
)
|
||||
audit_id = result.get("script", {}).get("id")
|
||||
ScriptAuditModel.objects.update_or_create(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
),
|
||||
defaults={"status": States.STARTED}
|
||||
)
|
||||
audit = NeutralAudit(audit_id, False)
|
||||
status = ScriptAuditModel.objects.get(
|
||||
script=Script.objects.get(
|
||||
id=audit_id
|
||||
)
|
||||
)
|
||||
try:
|
||||
audit.audit()
|
||||
status.status = "SUCCESS"
|
||||
status.save()
|
||||
print("----> Script id from conv-aud is here=", audit_id)
|
||||
translation_instance.converted_audit_id = audit_id
|
||||
translation_instance.save()
|
||||
except:
|
||||
status.status = "FAILURE"
|
||||
status.save()
|
||||
|
||||
|
||||
|
||||
sys.stdout = original_stdout
|
||||
|
|
Loading…
Reference in New Issue