-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd0708f
commit fb4ce0d
Showing
4 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from starlette.status import HTTP_400_BAD_REQUEST | ||
|
||
from app.web.exception.base_exception import BaseCustomException | ||
from app.web.exception.enum.error_enum import ErrorEnum | ||
|
||
|
||
class CodeVisualizeError(BaseCustomException): | ||
def __init__(self, error_enum: ErrorEnum, result: dict = None): | ||
super().__init__( | ||
status_code=HTTP_400_BAD_REQUEST, error_enum=error_enum, result={} if result is None else result | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import requests | ||
from app.config.settings import Settings | ||
from app.route.execute.exception.code_visualize_error import CodeVisualizeError | ||
from app.web.exception.enum.error_enum import ErrorEnum | ||
|
||
|
||
def analyze_code(source_code: str, user_input: str): | ||
visualise_url = "/".join([Settings.ENGINE_SERVER, "v1", "python"]) | ||
success_response = requests.post( | ||
response = requests.post( | ||
visualise_url, | ||
json={"source_code": source_code, "input": user_input} | ||
) | ||
return success_response.json().get("result").get("code") | ||
if not response.ok: | ||
raise CodeVisualizeError(ErrorEnum.CODE_VISUALIZE_ERROR) | ||
|
||
return response.json().get("result").get("code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters