diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd314f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./kitchen_counter/media/ diff --git a/kitchen_counter/conversion/translation/external_conversion.py b/kitchen_counter/conversion/translation/external_conversion.py index 95e4435..e091e1f 100644 --- a/kitchen_counter/conversion/translation/external_conversion.py +++ b/kitchen_counter/conversion/translation/external_conversion.py @@ -1,14 +1,17 @@ import sys - +import os +import boto3 import pandas as pd import datetime +import json +import tempfile # django from django.core.files.base import ContentFile # all external imports from scriptAudit.models import States -from centralisedFileSystem.models import Script +from centralisedFileSystem.models import Script, File from scriptAudit.models import ScriptAuditModel from mnfapp.models import MNFScriptDatabase, SampleScript, ScriptTranslations from users.models import UserCredentialsForBlockchain,BlockchainUserInfo @@ -18,7 +21,7 @@ from centralizePayment.views import auto_refund from juggernaut.views import update_juggernaut from auto_email.views import sendmail from lpp.views import task_assigner -from utils import filesystem +from utils import filesystem, utilities from conversion.translation.newconversion import ScriptTranslation from scriptAudit.mnf_script_audit import NeutralAudit from Blockchain2.DataStorage import uploadDataToIPFSNode @@ -499,8 +502,6 @@ class Conversion: 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", @@ -543,6 +544,37 @@ class Conversion: scriptconversion["translated_scriptFile_hash"] = hash scriptconversion["translated_scriptFile_path"] = translated_scripttt print("blockchain script conversion 5") + + print("audit blockchain") + print("blockchain script conversion 5.1") + # blockchain upload of csv-json data + adit_id = obj.converted_audit_id + + file_to_audit = File.objects.get( + script=adit_id, + type="script-csv" + ) + csv_script_path = file_to_audit.file.path + df = pd.read_csv(csv_script_path) + df = df.loc[:, ["content", "script_element"]] + script_json: dict = json.loads(utilities.csv_to_json(df)) + with tempfile.TemporaryDirectory() as temp_dir: + print("Temporary directory created:", temp_dir) + temp_filename = os.path.join(temp_dir, 'script_json_file.json') + print(temp_filename) + with open(temp_filename, 'w') as json_file: + json.dump(script_json, json_file, indent=4) + script_json = {} + script_path1 = temp_filename + # script_size = file_to_audit_docx.file.size + with open(script_path1, 'rb') as _file: + hash2 = uploadDataToIPFSNode(_file) + script_json["script_file_path"] = script_path1 + script_json["script_file"] = hash2 + script_json["type"] = "script-json" + scriptconversion["script-json"] = script_json + print("blockchain script conversion 5.2") + blockchain_obj = UserCredentialsForBlockchain.objects.get(user=self.user) UserId = blockchain_obj.user_id Project = obj.translation_id