141 lines
6.3 KiB
Python
Executable File
141 lines
6.3 KiB
Python
Executable File
from conversion.translation.twostepconversion import translate_function
|
|
import json,os
|
|
from pymongo import MongoClient
|
|
from openpyxl import Workbook
|
|
# from .detection import getInputs
|
|
|
|
wb = Workbook()
|
|
ws = wb.active
|
|
testdata = [['Script','non_dial_src_lang','dial_src_lang','dial_src_script','non_dial_dest_lang','dial_dest_lang','dial_dest_script','Outcome','Error']]
|
|
for data in testdata:
|
|
ws.append(data)
|
|
client = MongoClient('mongodb+srv://mynextfilm:mnf123@cluster0.ojasb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')
|
|
db = client.DB
|
|
|
|
languages_json_file = open('/home/user/mnf/project/MNF/conversion/translation/lls.json')
|
|
data_json = json.load(languages_json_file)
|
|
languages_condes_json_file = open('/home/user/mnf/project/MNF/conversion/translation/lls2.json')
|
|
data_json2 = dict(json.load(languages_condes_json_file))
|
|
languages_transliteration_json_file = open('/home/user/mnf/project/MNF/conversion/translation/scripts.json')
|
|
data_json3 = json.load(languages_transliteration_json_file)
|
|
|
|
option3 = "Yes"
|
|
option4 = "Yes"
|
|
option5 = "Yes"
|
|
option6 = "Yes"
|
|
restrict_to_five = "yes"
|
|
dual_dial_script = "No"
|
|
|
|
def test_run():
|
|
scripts = [["/home/user/mnf/project/MNF/media/scripts/fddfd.docx", "en", "en", "Latin", "Latin"]]
|
|
script_ids = ["scr_001"]
|
|
for scripti,script_id in zip(scripts,script_ids):
|
|
user_script_data = db["mnfapp_mnfscriptdatabase"].find_one({"script_id": script_id})
|
|
|
|
#for now hard-coding but should be dynamic
|
|
# dial_src_lang = "en"
|
|
# non_dial_src_lang = "en"
|
|
# dial_src_script = "Latin"
|
|
|
|
allow_translations = 0
|
|
|
|
script = scripti[0]
|
|
dial_src_script = scripti[3]
|
|
dial_src_lang = scripti[1]
|
|
non_dial_src_lang = scripti[2]
|
|
action_line_src_script = scripti[4]
|
|
|
|
for i in data_json:
|
|
if i['codeSrc'] == dial_src_lang:
|
|
dial_dest_lang_list = i['options']
|
|
if i['codeSrc'] == non_dial_src_lang:
|
|
non_dial_dest_lang_list = i['options']
|
|
|
|
for i in non_dial_dest_lang_list:
|
|
for j in dial_dest_lang_list:
|
|
for ii in data_json:
|
|
if str(ii['key']) == str(i):
|
|
non_dial_dest_lang = ii['codeSrc']
|
|
if str(ii['key']) == str(j):
|
|
dial_dest_lang = ii['codeSrc']
|
|
if dial_dest_lang == "ug":
|
|
allow_translations = 1
|
|
# for i in data_json2:
|
|
# if i ==
|
|
# print("********************---------------------777777799999999---------***************************")
|
|
# print(data_json2['Hindi'])
|
|
try:
|
|
dial_dest_script = data_json2[str(j)]
|
|
except:
|
|
dial_dest_script = "Latin"
|
|
print("dsdsdssssd12")
|
|
print(dial_dest_script)
|
|
for i in data_json3:
|
|
print(i)
|
|
print(i['key'])
|
|
if i['key'] == dial_dest_script:
|
|
scripts = i['options']
|
|
|
|
for script_to_be_transliterated_in in scripts:
|
|
dial_dest_script = str(script_to_be_transliterated_in)
|
|
user_script_data["nondial_dest_language"] = str(non_dial_dest_lang)
|
|
user_script_data["dial_dest_language"] = str(dial_dest_lang)
|
|
user_script_data["dual_dial_script"] = str(dual_dial_script)
|
|
user_script_data["dial_dest_script"] = str(dial_dest_script)
|
|
user_script_data["nondial_src_script"] = str(action_line_src_script)
|
|
db["mnfapp_mnfscriptdatabase"].save(user_script_data)
|
|
|
|
print("11 Entering Function")
|
|
|
|
try:
|
|
if allow_translations == 1:
|
|
filename = translate_function(
|
|
script,
|
|
script_id,
|
|
dial_src_lang,
|
|
non_dial_src_lang,
|
|
dial_src_script,
|
|
restrict_to_five,
|
|
option3,
|
|
option4,
|
|
option5,
|
|
option6,
|
|
)
|
|
testdata = [[str(script), str(non_dial_src_lang), str(dial_src_lang), str(dial_src_script),
|
|
str(non_dial_dest_lang),
|
|
str(dial_dest_lang), str(dial_dest_script), 'PASS', 'NOTHING']]
|
|
print("11 Saving here")
|
|
for data in testdata:
|
|
ws.append(data)
|
|
wb.save("/home/user/mnf/project/MNF/media/file_11.xlsx")
|
|
# db["mnfapp_mnfscriptdatabase"].save(user_script_data)
|
|
# if os.path.exists("/home/user/mnf/project/MNF/media/"+str(user_script_data['translated_script_path'])):
|
|
# os.remove("/home/user/mnf/project/MNF/media/"+str(user_script_data['translated_script_path']))
|
|
except Exception as e:
|
|
print("11 Some Error Encountered")
|
|
testdata = [[str(script), str(non_dial_src_lang), str(dial_src_lang), str(dial_src_script),
|
|
str(non_dial_dest_lang),
|
|
str(dial_dest_lang), str(dial_dest_script), 'FAIL', str(e)]]
|
|
for data in testdata:
|
|
ws.append(data)
|
|
wb.save("/home/user/mnf/project/MNF/media/file_11.xlsx")
|
|
break
|
|
|
|
wb.save("file_" + str(script) + ".xlsx")
|
|
return True
|
|
|
|
|
|
# filename = translate_function(
|
|
# script_file_path,
|
|
# script_id,
|
|
# dial_src_lang,
|
|
# non_dial_src_lang,
|
|
# dial_src_script,
|
|
# restrict_to_five,
|
|
# option3,
|
|
# option4,
|
|
# option5,
|
|
# option6,
|
|
# )
|
|
|