-
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.
Merge pull request #53 from RobsOnWaves/develop
Develop
- Loading branch information
Showing
4 changed files
with
164 additions
and
23 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,52 @@ | ||
import datetime | ||
import re | ||
import threading | ||
from io import BytesIO | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from docx import Document | ||
from fastapi import UploadFile | ||
from libs.messages import Messages | ||
from openpyxl import load_workbook | ||
from openpyxl.styles import Alignment | ||
from unidecode import unidecode | ||
import shutil | ||
import tempfile | ||
|
||
|
||
class MepsHandler: | ||
def __init__(self): | ||
self.__messages__ = Messages() | ||
self.__max_length__ = 1000 | ||
self.__timeout_duration__ = 60 | ||
|
||
class TimeoutException(Exception): | ||
pass | ||
|
||
def timeout_handler(self): | ||
raise self.TimeoutException() | ||
|
||
async def load_csv_file(self, upload_file: UploadFile, answer: dict = None): | ||
|
||
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file: | ||
# Copier le contenu de l'objet UploadFile dans le fichier temporaire | ||
shutil.copyfileobj(upload_file.file, temp_file) | ||
temp_file_path = temp_file.name | ||
|
||
# Extract the table | ||
timer = threading.Timer(self.__timeout_duration__, self.timeout_handler) | ||
try: | ||
timer.start() | ||
df = pd.read_csv(temp_file_path) | ||
answer["df"] = df | ||
answer["success"] = True | ||
return answer | ||
except self.TimeoutException: | ||
answer["df"] = None | ||
answer["success"] = False | ||
return self.__messages__.nok_string | ||
finally: | ||
# Arrête le timer | ||
timer.cancel() | ||
|
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
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