Upload batches of users onto firebase

This commit is contained in:
Carlos Mesquita
2024-09-03 20:09:19 +01:00
parent 06a8384f42
commit 7b5e10fd79
9 changed files with 336 additions and 15 deletions

View File

@@ -3,7 +3,8 @@ import io
import os
import shutil
import subprocess
from typing import Optional
import uuid
from typing import Optional, Tuple
import numpy as np
import pypandoc
@@ -75,3 +76,22 @@ class FileHelper:
shutil.rmtree(path)
except Exception as e:
print(f"An error occurred while trying to remove {path}: {str(e)}")
@staticmethod
def remove_file(file_path):
try:
if os.path.exists(file_path):
if os.path.isfile(file_path):
os.remove(file_path)
except Exception as e:
print(f"An error occurred while trying to remove the file {file_path}: {str(e)}")
@staticmethod
def save_upload(file) -> Tuple[str, str]:
ext = file.filename.split('.')[-1]
path_id = str(uuid.uuid4())
os.makedirs(f'./tmp/{path_id}', exist_ok=True)
tmp_filename = f'./tmp/{path_id}/uploaded.{ext}'
file.save(tmp_filename)
return ext, path_id