@@ -596,6 +656,9 @@
fade_elements[0].classList.remove("modal-backdrop");
window.location.reload();
}
+ function closeFeedback(){
+ document.getElementById('feedback-thanks-container').style.display="none";
+ }
diff --git a/kitchen_counter/scriptAudit/urls.py b/kitchen_counter/scriptAudit/urls.py
index e2e64bc..5305671 100755
--- a/kitchen_counter/scriptAudit/urls.py
+++ b/kitchen_counter/scriptAudit/urls.py
@@ -4,6 +4,8 @@ from django.views.generic import TemplateView
urlpatterns = [
path("home", views.AuditHomeView.as_view(), name="upload_audit"),
+ path("counter_run", views.Get_Counter.as_view(), name="counter_run"),
+ path("fetch_in_counter", views.Fetch_in_Counter.as_view(), name="fetch_in_counter"),
path("facade", views.AuditFacadeView.as_view(), name="upload_audit_facade"),
path("facade/status_update", views.AuditStatusUpdate.as_view(), name="audit_facade_status_update"),
path("facade/file_update", views.AuditedFileUpdate.as_view(), name="audit_facade_file_update"),
diff --git a/kitchen_counter/scriptAudit/views.py b/kitchen_counter/scriptAudit/views.py
index f355727..112c78a 100755
--- a/kitchen_counter/scriptAudit/views.py
+++ b/kitchen_counter/scriptAudit/views.py
@@ -5,8 +5,11 @@ from rest_framework_simplejwt.authentication import JWTAuthentication
import tempfile
import requests
import pandas as pd
+import boto3
from io import BytesIO
+from django.contrib.auth.models import User
import json
+import shutil
from users.models import UserCredentialsForBlockchain
from Blockchain2.block_user_info import *
from Blockchain2.decryption import decryptionOfPrivate, decryptionOfUrl, download_file_System,decryptionOflocalUrl,hash_decrypation
@@ -51,6 +54,8 @@ from utils.filesystem import get_file,get_file_path, get_script_data
# from utils.utilities import send_email_to_user
# from narration.vectorcode.code import vector_generation
from auto_email.views import sendmail
+from MNF import settings
+from django.contrib.auth.models import User
# from mnfapp.views import update_juggernaut
# from mnfapp.views import check_juggernaut
# from Pitchdeck.views import multilingual_render
@@ -193,6 +198,404 @@ class AuditFacadeView(APIView):
# return HttpResponseBadRequest(render(request, "audit/audit.html", {"form": form,"errors": form.errors}))
+class Get_Counter(APIView):
+ authentication_classes = [BasicAuthentication,SessionAuthentication]
+ permission_classes = [IsAuthenticated]
+
+
+ def get(self, request):
+ return render(request, "audit/audit_AWS_home.html")
+
+ def post(self, request):
+ # session = boto3.Session(
+ # aws_access_key_id='AKIAQVLBBGCB45RMLKVW', # replace with your key
+ # aws_secret_access_key='ZWc6KOc5LuBLuCEBDDfQTor+Q7rp3fFH74gVt+AA', # replace with your key
+ # )
+ # sqs = session.resource('sqs', region_name='ap-south-1')
+ # queue = sqs.get_queue_by_name(QueueName="mnfqueue")
+
+
+ user = str(request.user)
+ screenplay_name = request.data.get('screenplay_name')
+ author = request.data.get('author_name')
+ language = request.data.get('language')
+ script_file = request.data.get('script_file')
+ script_ext = script_file.name.split(".")[-1]
+ script_file_name = screenplay_name + "." + script_ext
+
+ media_path = os.path.join(settings.MEDIA_ROOT,"audit_counter_files", script_file_name)
+ with open(media_path, 'wb') as destination:
+ for chunk in script_file.chunks():
+ destination.write(chunk)
+
+ # object_name = "INPUT/" + script_file_name
+ # filee = media_path
+ # 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)
+ # print(response)
+ # except Exception as e:
+ # print("Error is", e)
+
+
+ # s3_url = f"https://{bucket}.s3.ap-south-1.amazonaws.com/{object_name}"
+
+ audit_parameters = {
+ "service_type" : "audit",
+ "user":user,
+ # "s3-file-path": s3_url,
+ "s3-file-path": media_path,
+ "screenplay_name": screenplay_name,
+ "author": author,
+ "language": language,
+ "script_ext": script_ext,
+ "script_file_name": script_file_name
+ }
+ print("################ AUDIT PARAMETER", audit_parameters)
+ # response = queue.send_message(
+ # MessageBody=json.dumps(audit_parameters),)
+
+ return JsonResponse({"response": audit_parameters})
+ # return redirect("new_audited_page")
+
+
+class Fetch_in_Counter(APIView):
+ authentication_classes = [BasicAuthentication,SessionAuthentication]
+ permission_classes = [IsAuthenticated]
+ def post(self, request):
+ audit_parameters = request.data
+ print(audit_parameters)
+ # time.sleep(7)
+ user = audit_parameters.get("user")
+ s3_url = audit_parameters.get("s3-file-path")
+ screenplay_name = audit_parameters.get("screenplay_name")
+ author = audit_parameters.get("author")
+ language = audit_parameters.get("language")
+ script_ext = audit_parameters.get("script_ext")
+ script_file_name = audit_parameters.get("script_file_name")
+ language = "en" # main language
+
+ if script_ext == "docx":
+ pass
+
+ elif script_ext == "pdf":
+ pass
+
+ elif script_ext == "fdx":
+ estimatedtime = None
+
+ else: #txt
+ pass
+ with open(s3_url, 'rb') as file:
+ file_content = file.read()
+
+ file = ContentFile(
+ file_content,
+ script_file_name,
+ )
+ # user = User.objects.get(username=user)
+ # user_id = user.id
+
+ result = filesystem.new_screenplay_without_audit_in_background(
+ request.user,
+ author,
+ screenplay_name,
+ file,
+ "script-original",
+ language,
+ )
+
+
+ script_id = result.get("script", {}).get("id")
+
+ file_to_original = File.objects.get(
+ script=script_id,
+ type="script-original"
+
+ )
+ try:
+ update_audit_status(script_id, States.STARTED)
+ except:
+ update_audit_status(script_id, States.FAILURE)
+
+
+ try:
+ # audit_in_background(script_id)
+ audit = NeutralAudit(script_id)
+ audit.audit_in_background()
+ ScriptAuditModel.objects.update_or_create(
+ script = Script.objects.get(
+ id = script_id
+ ),
+ defaults={"status" : "SUCCESS"}
+ )
+ #script_id will be present here as well
+ # blockchain code to upload files,
+ #1. csv
+ #2. Audit Orginal
+ #3. Audit Report
+ #4. Audit Docx
+ #5. Audit PDF
+
+
+
+ except:
+ ScriptAuditModel.objects.update_or_create(
+ script = Script.objects.get(
+ id = script_id
+ ),
+ defaults={"status" : "FAILURE"}
+ )
+
+ status = ScriptAuditModel.objects.get(
+ script = Script.objects.get(
+ id = script_id
+ ))
+ print("STATUS AUDIT",status)
+ # Blockchain
+ # if UserCredentialsForBlockchain.objects.filter(user=request.user).exists():
+ blockchain_obj = UserCredentialsForBlockchain.objects.get(user=request.user)
+ script_original= {}
+ audit_data={}
+ script_original["status"] = "STARTED"
+ script_original["script_id"] = script_id
+ with open(file_to_original.file.path, 'rb') as file:
+ hash = uploadDataToIPFSNode(file)
+ script_original["script_file"] = hash
+ script_original["type"] = "script-original"
+ script_original["script_file_path"] = file_to_original.file.path
+ audit_data["script-original"] = script_original
+ userkey= decryptionOfPrivate(blockchain_obj.privateKey)
+ print("userkey = ", str(userkey))
+ # status,getData = getScriptAudit(userkey.decode('utf-8'),user_id,str(script_id))
+ # privatekeyfordb = userkey.decode('utf-8')
+ # print(privatekeyfordb)
+ # status.bchain_privatekey = privatekeyfordb
+ # status.save()
+ print("blockchain_obj.publicKey",blockchain_obj.publicKey)
+ print("blockchain_obj.privateKey",blockchain_obj.privateKey)
+ if status.status == "SUCCESS":
+ file_to_audit = File.objects.get(
+ script=script_id,
+ type="script-csv"
+ )
+ file_to_audit_report = File.objects.get(
+ script=script_id,
+ type="audit-report"
+ )
+ hash2 = ""
+ try:
+ file_to_audit_docx = File.objects.get(
+ script=script_id,
+ type="script-docx"
+ )
+ script_docx = {}
+ script_path1 = file_to_audit_docx.file.path
+ with open(script_path1, 'rb') as _file:
+ hash2 = uploadDataToIPFSNode(_file)
+ script_docx["script_file_path"] = script_path1
+ script_docx["script_file"] = hash2
+ script_docx["type"] = "script-docx"
+ audit_data["script-docx"] = script_docx
+ except:
+ csv_script_path = file_to_audit.file.path
+ df = pd.read_csv(csv_script_path)
+ docx = utilities.csv_to_docx(df)
+
+ temp_file_stream = BytesIO()
+ docx.save(temp_file_stream)
+ temp_file_stream.seek(0)
+
+ docx_file = ContentFile(
+ temp_file_stream.getvalue(),
+ "from_audited_csv_to_document.docx",
+ )
+
+ query_file = File.objects.create(
+ script= file_to_audit.script,
+ file=docx_file,
+ type="script-docx",
+ )
+ file_to_audit_docx = File.objects.get(
+ script=script_id,
+ type="script-docx"
+ )
+ script_docx = {}
+ script_path1 = file_to_audit_docx.file.path
+ script_size = file_to_audit_docx.file.size
+ with open(script_path1, 'rb') as _file:
+ hash2 = uploadDataToIPFSNode(_file)
+ script_docx["script_file_path"] = script_path1
+ script_docx["script_file"] = hash2
+ script_docx["type"] = "script-docx"
+ audit_data["script-docx"] = script_docx
+
+ ## code for pdf also
+ try:
+ temp_dir = tempfile.TemporaryDirectory()
+ pdf_file_path = utilities.docx_to_pdf(
+ script_path1, temp_dir.name)
+
+ with open(pdf_file_path, "rb") as temp_pdf:
+
+ pdf_file = DjangoFile(temp_pdf,pdf_file_path.rsplit('/', 1)[1],)
+
+ query_file = File.objects.create(
+ script = file_to_audit.script,
+ file = pdf_file,
+ type="script-pdf",
+ )
+ script_pdf = {}
+ script_path1 = pdf_file_path
+ # script_size = file_to_audit_docx.file.size
+ with open(script_path1, 'rb') as _file:
+ hash2 = uploadDataToIPFSNode(_file)
+ script_pdf["script_file_path"] = script_path1
+ script_pdf["script_file"] = hash2
+ script_pdf["type"] = "script-pdf"
+ audit_data["script-pdf"] = script_pdf
+ except:
+ pass
+ # convert csv to json and store JSON
+ try:
+ 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"
+ audit_data["script-json"] = script_json
+ except:
+ pass
+
+ script_csv = {}
+ audit_report ={}
+ audit_report_path = file_to_audit_report.file.path
+ script_path = file_to_audit.file.path
+ script_size = file_to_audit.file.size
+
+ print("script_file_path_is_here",script_path)
+ with open(script_path, 'rb') as _file:
+ hash1 = uploadDataToIPFSNode(_file)
+ script_csv["script_file"] = hash1
+ script_csv["script_file_path"] = script_path
+ script_csv["type"] = "script-csv"
+ with open(audit_report_path, 'rb') as file1:
+ hash2 = uploadDataToIPFSNode(file1)
+ audit_report["script_file"] = hash2
+ audit_report["script_file_path"] = audit_report_path
+ audit_report["type"] = "audit-report"
+ audit_data["script-csv"]= script_csv
+ audit_data["audit-report"]= audit_report
+
+ with open("/home/mnftaj/mnf_march22/MNF/app/Blockchain2/file_stroge.txt","a") as file01:
+ file01.write("audit userkey------------------SUCCESS1 IN_COUNTER\n" + str(audit_data) + "\n")
+ Response,gasprice = UploadScriptAuditData(OWNER_KEY,blockchain_obj.publicKey,blockchain_obj.user_id,script_id,str(audit_data))
+ print("tx_hash",Response)
+ with open("/home/mnftaj/mnf_march22/MNF/app/Blockchain2/file_stroge.txt","a") as file01:
+ file01.write("audit userkey------------------SUCCESS\n"+str(Response))
+ transactioni_id = str(Response)
+ # with open("/home/mnfbeta/mnf/app/Blockchain2/file_stroge.txt","a") as file01:
+ # file01.write(f"Transaction hash for audit is {str(transactioni_id)}\n")
+ # current_time = datetime.now()
+ # formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
+ # file01.write(f"Transaction hash for audit is {str(type(transactioni_id))}\n")
+ # file01.write(f" time for the above transaction id {str(formatted_time)}\n")
+ # audit_model_obj = ScriptAuditModel.objects.get(
+ # script = Script.objects.get(id = script_id))
+ status.transaction_hash =str(transactioni_id)
+ # audit_model_obj.transaction_hash = str(transactioni_id)
+ # audit_model_obj.save()
+ status.save()
+
+ # user_infos = user_info(tx_hash=Response,service="Script Audit",gas_fee=gasprice)
+ # addition_result = user_infos.update_info(request)
+ hash2 = hash_decrypation(hash2)
+ tx_id = Response
+ certificate = certificateGenrate(request.user.username,"script audit",tx_id,projectname=script_file_name,matic=gasprice)
+ to_email = [request.user.email]
+ email_code = 'BL1'
+ key_value = {
+ "service":"Audited Script",
+ "hash": hash2,
+ "public key":blockchain_obj.publicKey,
+ "Transaction Hash": tx_id,
+ }
+ print("userkey = ", userkey)
+ sendmail(to_email=to_email , email_code=email_code, key_value=key_value, filePath=certificate)
+ print("mail send sucessfully:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
+ data = {"message": "Success"}
+ # deleting the folder and files
+
+ # Delete a file
+ media_path = os.path.join(settings.MEDIA_ROOT, "audit_counter_files", script_file_name)
+ if os.path.exists(media_path):
+ os.remove(media_path)
+ print(f"File '{media_path}' deleted successfully.")
+ else:
+ print(f"File '{media_path}' does not exist.")
+
+ # Delete a folder and its contents
+ folder1_path = os.path.join(settings.MEDIA_ROOT, "scripts_folder", script_id)
+ if os.path.exists(folder1_path):
+ shutil.rmtree(folder1_path)
+ print(f"Folder '{folder1_path}' and its contents deleted successfully.")
+ else:
+ print(f"Folder '{folder1_path}' does not exist.")
+
+ folder2_path = os.path.join(settings.MEDIA_ROOT, "audit_folder", script_id)
+ if os.path.exists(folder2_path):
+ shutil.rmtree(folder2_path)
+ print(f"Folder '{folder2_path}' and its contents deleted successfully.")
+ else:
+ print(f"Folder '{folder2_path}' does not exist.")
+ return JsonResponse(data, status=200)
+ # return Response("Success", status=200)
+
+
+ else:
+ with open("/home/mnftaj/mnf_march22/MNF/app/Blockchain2/file_stroge.txt","a") as file01:
+ file01.write("audit userkey------------------else\n")
+ Response = UploadScriptAuditData(OWNER_KEY,blockchain_obj.publicKey,blockchain_obj.user_id,script_id,str(audit_data))
+ print("tx_hash",Response)
+ hash = hash_decrypation(hash)
+ #certificate = certificateGenrate(request.user.username,"script audit",hash)
+ tx_id = Response
+
+ # certificate = certificateGenrate(request.user.username,"script audit",tx_id,projectname=script_file_name,matic=gasprice)
+
+ to_email = [request.user.email]
+ email_code = 'BL1'
+ key_value = {
+ "service":"Orginal Script Audit",
+ "hash": hash,
+ "public key":blockchain_obj.publicKey,
+ "private key":userkey,
+ "Transaction Hash": tx_id,
+ }
+
+ print("::::::::::::::",key_value)
+ print("userkey = ", userkey)
+ # sendmail(to_email=to_email , email_code=email_code,key_value=key_value,filePath=certificate)
+ return JsonResponse({"script_id": script_id}, status=200)
+
class AuditStatusUpdate(APIView):
def post(self,request):
@@ -510,12 +913,12 @@ class AuditHomeView(APIView):
with open(audit_report_path, 'rb') as file1:
hash2 = uploadDataToIPFSNode(file1)
audit_report["script_file"] = hash2
- script_csv["script_file_path"] = audit_report_path
- script_csv["type"] = "audit-report"
+ audit_report["script_file_path"] = audit_report_path
+ audit_report["type"] = "audit-report"
audit_data["script-csv"]= script_csv
audit_data["audit-report"]= audit_report
with open("/home/mnftaj/mnf_march22/MNF/app/Blockchain2/file_stroge.txt","a") as file01:
- file01.write("audit userkey------------------SUCCESS1\n")
+ file01.write("audit userkey------------------SUCCESS1 HOME AUDIT\n")
Response,gasprice = UploadScriptAuditData(OWNER_KEY,blockchain_obj.publicKey,blockchain_obj.user_id,script_id,str(audit_data))
print("tx_hash",Response)
with open("/home/mnftaj/mnf_march22/MNF/app/Blockchain2/file_stroge.txt","a") as file01:
@@ -612,7 +1015,7 @@ class AuditHomeView(APIView):
# audit_in_background(script_id)
# time.sleep(3)
# return redirect("my_audited_scripts")
- return redirect("audit_processing_page")
+ return redirect("new_audited_page1")
# return multilingual_render(request, "audit/audit_processing.html", None)
else :
# return HttpResponseBadRequest(multilingual_render(request, "audit/audit.html", {"form": form,"errors": form.errors}))
@@ -937,7 +1340,7 @@ class DownloadScriptFromBlockchain(APIView):
View for downloding scripts of desired type eg- docx, pdf
"""
- VALID_FILE_TYPES = ("script-docx", "script-pdf","script-original","audit-report")
+ VALID_FILE_TYPES = ("script-docx", "script-pdf","script-original","audit-report","script-json")
"""
Files of only above types are allwed to be downloaded.
"""
@@ -988,7 +1391,36 @@ class DownloadScriptFromBlockchain(APIView):
if not self.file_model_objects.exists():
raise spex.ScriptDoesNotExist()
-
+ if file_type == "script-json":
+ try:
+ # self.query_file = self.file_model_objects.get(type=file_type)
+ try:
+ query_file1 = self.auditData.get(file_type)
+ print("###########", str(self.auditData))
+ file_hash = query_file1.get('script_file')
+ file_name = str((str(query_file1['script_file_path']).split("/"))[-1])
+ geting_files = str(decryptionOflocalUrl(file_hash))
+ print("########GETTING",geting_files )
+ print(type(geting_files))
+ # Fetch the JSON data from the URL
+ response = requests.get(str(geting_files))
+ print("#####RESPONSE####", response)
+ if response.status_code == 200:
+ # Parse the JSON data
+ json_data = response.json()
+ print("##########JSON DATA #######")
+ print(json_data)
+ # Return the JSON data as a response
+ return JsonResponse({"script-json": json_data}, status=200)
+ return JsonResponse({"response didnt work": str(geting_files), "message": "File type is script-json"}, status=200)
+ except Exception as exp:
+ # err = repr(exp)
+ return JsonResponse({"fail": repr(exp), "message": "File type is script-json"}, status=400)
+ except:
+ pass
+
+ return JsonResponse({"failing": "not----", "message": "File type is script-json"}, status=400)
+
try:
self.query_file = self.file_model_objects.get(type=file_type)
try:
diff --git a/kitchen_counter/users/models.py b/kitchen_counter/users/models.py
index 8c4763e..9b7d388 100755
--- a/kitchen_counter/users/models.py
+++ b/kitchen_counter/users/models.py
@@ -141,7 +141,7 @@ class BlockchainUserInfo(models.Model):
user_name = models.CharField(max_length=100,blank=True, null=True)
tx_hash = models.CharField(max_length=100,blank=True, null=True)
service = models.CharField(max_length=100,blank=True, null=True)
- gas_fee = models.IntegerField(max_length=100)
+ gas_fee = models.CharField(max_length=100,blank=True, null=True)
script_name = models.CharField(max_length=100,blank=True, null=True)
uploaded_by = models.CharField(max_length=100,blank=True, null=True)
upload_date = models.DateField(auto_now_add=True)