diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d5dd92f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "name": "Python Debugger: FastAPI", + "type": "debugpy", + "request": "launch", + "module": "uvicorn", + "args": [ + "main:app", + "--reload" + ], + "jinja": true + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d7eb03 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.14 + +WORKDIR /code +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +COPY . /code/ + +CMD ["fastapi", "run", "app/main.py", "--port", "80"] \ No newline at end of file diff --git a/convert-to-json.py b/__init__.py similarity index 100% rename from convert-to-json.py rename to __init__.py diff --git a/convert_to_json.py b/convert_to_json.py new file mode 100644 index 0000000..e59b9ef --- /dev/null +++ b/convert_to_json.py @@ -0,0 +1,21 @@ +from fastapi import UploadFile +from correpy.parsers.brokerage_notes.parser_factory import ParserFactory +import logging + + + + + + +# Check if requires password based on file name +async def open_file(file: UploadFile): + + brokerage_notes = None + + # Rico + if "11775539" in file.filename: + logger.info("[convert_to_json] Reading Rico notes") + #brokerage_notes = ParserFactory(brokerage_note=content, password=RICO_PASSW).parse() + + + print(brokerage_notes) \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..78a44a8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + brokerage-note-converter: + container_name: brokerage-note-converter + build: . + dockerfile: Dockerfile + ports: + - "8000:80" + restart: unless-stopped + diff --git a/main.py b/main.py index 520c76f..9e0f68f 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,28 @@ -from fastapi import FastAPI +from fastapi import FastAPI, File, UploadFile +import logging +from correpy.parsers.brokerage_notes.parser_factory import ParserFactory + + +logging.basicConfig() +logger = logging.getLogger('uvicorn.error') app = FastAPI() +RICO_PASSW = "052" @app.get("/") def read_root(): return {"Hello": "World"} -@app.get("/test") -def test(): - return "Test" \ No newline at end of file +@app.post("/convert-brokerage-note") +async def convert_brokerage_note(file: UploadFile): + + content = file.file.read() + + if "11775539" in file.filename: + logger.info("Parsing Rico note") + brokerage_notes = ParserFactory(brokerage_note=content, password=RICO_PASSW).parse() + + + return {"fileName": file.filename, "result": brokerage_notes} \ No newline at end of file diff --git a/test/NotaNegociacao-11775539-04-11-2025-0.pdf b/test/NotaNegociacao-11775539-04-11-2025-0.pdf new file mode 100644 index 0000000..e2556af Binary files /dev/null and b/test/NotaNegociacao-11775539-04-11-2025-0.pdf differ