# from scriptAudit.mnf_script_audit import NeutralAudit # from django.core.files.base import File as DjangoFile # from django.core.files.base import ContentFile # from centralisedFileSystem.models import Script,File, ScreenPlay # from .utils import update_audit_status """ class ScriptTranslation(APIView): """ #below code is writting bt paveen #logics: #1. PDF,FDX,DOCX,TXT file to be converted into text file #2. 50 Lines are extracted from the text file #3. """ from scriptAudit.mnf_script_audit import NeutralAudit def get(self, request): form = CScript() return render(request, "conversion/conversion.html", {"form": form}) def post(self,request): #considering the file comes in request.FILES input_script = filename1 output_docx = rf"{basePath}/conversion/translation/file_lines.docx" output_txt = rf"{basePath}/conversion/translation/file_lines.txt" conv_to_txt(input_script,output_docx,output_txt) script_file = output_txt script_ext = os.path.splitext(script_file)[1][1:] script_file_name = screenplay_name + "." + script_ext file = ContentFile( script_file.read(), script_file_name, ) result = filesystem.new_screenplay_without_audit_in_background( request.user, author, screenplay_name, file, "script-original", language, ) audit_script_id = result.get("script", {}).get("id") try: audit = NeutralAudit(audit_script_id) except Exception as exp: #preaudit to extract first 50 pages failed #add unsuccessfu mail here for preaudit print({"error:" + f"Failed to create NeutralAudit: {str(e)}"}) return Response({"error": "Failed to start converison"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) 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") action_line50 = df.loc[df['script_element'] == 'action', 'content'].tolist() dialogue_line50 = df.loc[df['script_element'] == 'dialogue', 'content'].tolist() """ #action_line50 --> list #dialogue_line50 --> list #add code here to identify the action_line_language and dialogues language """ pass """ # def audit_file_with_scriptid(inputfile_path, script_id, source_lang, desi_lang): # file_to_audit = File.objects.get( # script=script_id, # type="script-original", # ) # new_content_path = inputfile_path # # Open the new content file and read its content # with open(new_content_path, 'rb') as new_file: # content = new_file.read() # # Update the existing File object with the new content # file_to_audit.file.save(file_to_audit.file.name, ContentFile(content)) # audit_model_obj = ScriptAuditModel.objects.get( # script = Script.objects.get( # id = script_id, # ) # ) # update_audit_status(script_id,"PENDING") # try: # audit = NeutralAudit(script_id) # audit.audit_in_background() # except: # print("Failed Status here") # pass # pass