Commit 4005c9f7 authored by mohammed.shibili's avatar mohammed.shibili

first change

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="SQLAlchemy" />
<item index="1" class="java.lang.String" itemvalue="psycopg2-binary" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="list.discard" />
<option value="Sheet_name" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (find and replace)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/find and replace.iml" filepath="$PROJECT_DIR$/.idea/find and replace.iml" />
</modules>
</component>
</project>
\ No newline at end of file
from fastapi import FastAPI, UploadFile, HTTPException
from typing import Dict, Any
import json
app = FastAPI()
def find_and_replace_recursive(data: Any, replacements: Dict[str, str]) -> Any:
if isinstance(data, dict):
for key, value in data.items():
data[key] = find_and_replace_recursive(value, replacements)
elif isinstance(data, list):
for i, item in enumerate(data):
data[i] = find_and_replace_recursive(item, replacements)
elif isinstance(data, str):
for old_text, new_text in replacements.items():
data = data.replace(old_text, new_text)
return data
@app.post("/replace_values")
async def replace_values(file: UploadFile = UploadFile(...)):
try:
content = await file.read()
json_data = json.loads(content)
replacements = {
"Value is Out of Spec": "Out of Spec",
"Please Enter Recheck Value": "Enter Recheck Value",
"Please Enter Comment": "Enter Comment",
"Please Enter Value": "Enter Value",
"AssociateAssetResource": "OplAssociateAssetResource",
"w-200px": ""
}
updated_json = find_and_replace_recursive(json_data, replacements)
return updated_json
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format in the uploaded file.")
import uvicorn
if __name__ == "__main__":
uvicorn.run("find and replace:app", port=8000, reload=True)
\ 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