Commit 04ead573 authored by mohammed.shibili's avatar mohammed.shibili

requirements

parent 62630947
from fastapi import FastAPI, UploadFile, HTTPException
from fastapi import FastAPI, UploadFile, HTTPException, Form, File
from typing import Dict, Any
import json
import chardet
app = FastAPI()
app = FastAPI()
......@@ -22,7 +25,9 @@ def find_and_replace_recursive(data: Any, replacements: Dict[str, str]) -> Any:
async def replace_values(file: UploadFile = UploadFile(...)):
try:
content = await file.read()
json_data = json.loads(content)
encoding_result = chardet.detect(content)
file_encoding = encoding_result['encoding']
json_data = json.loads(content.decode(file_encoding))
replacements = {
"Value is Out of Spec": "Out of Spec",
......@@ -30,11 +35,12 @@ async def replace_values(file: UploadFile = UploadFile(...)):
"Please Enter Comment": "Enter Comment",
"Please Enter Value": "Enter Value",
"AssociateAssetResource": "OplAssociateAssetResource",
"w-200px": ""
"text-center not-required w-200px": "text-center not-required"
}
updated_json = find_and_replace_recursive(json_data, replacements)
# add_component = {}
# updated_json["components"].insert(0, add_component)
return updated_json
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format in the uploaded file.")
......@@ -16,3 +16,5 @@ starlette==0.32.0.post1
typing-extensions==4.9.0
uvicorn==0.25.0
wheel==0.38.4
chardet~=5.2.0
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment