Skip to content

Commit

Permalink
fix: not building project after deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardofernandezz committed Nov 14, 2024
1 parent 54be72f commit 01e75eb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Binary file modified __pycache__/main.cpython-312.pyc
Binary file not shown.
33 changes: 32 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,43 @@ async def convert_json_to_excel(json_data: dict, original_filename: str):
Função auxiliar para converter JSON em Excel com formatação adequada
"""
try:
# Mapeamento de nomes de colunas (adicione mais conforme necessário)
column_mapping = {
'id': 'ID',
'name': 'Nome',
'email': 'E-mail',
'phone': 'Telefone',
'address': 'Endereço',
'created_at': 'Data de Criação',
'updated_at': 'Data de Atualização',
'status': 'Status',
'price': 'Preço',
'quantity': 'Quantidade',
'description': 'Descrição',
# Adicione mais mapeamentos conforme necessário
}

# Converte JSON para DataFrame
if isinstance(json_data, list):
df = pd.DataFrame(json_data)
else:
df = pd.DataFrame([json_data])

# Renomeia as colunas usando o mapeamento
df = df.rename(columns=lambda x: column_mapping.get(x, x.replace('_', ' ').title()))

# Formata colunas de data se existirem
date_columns = ['Data de Criação', 'Data de Atualização']
for col in date_columns:
if col in df.columns:
df[col] = pd.to_datetime(df[col]).dt.strftime('%d/%m/%Y %H:%M')

# Formata colunas de preço se existirem
price_columns = ['Preço']
for col in price_columns:
if col in df.columns:
df[col] = df[col].apply(lambda x: f'R$ {float(x):,.2f}' if pd.notnull(x) else '')

# Cria nome único para o arquivo Excel
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
excel_filename = f"uploads/{os.path.splitext(original_filename)[0]}_{timestamp}.xlsx"
Expand Down Expand Up @@ -188,4 +219,4 @@ async def convert_json_to_excel(json_data: dict, original_filename: str):

if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info")
Binary file added uploads/json_data_20241114_115131.xlsx
Binary file not shown.
Binary file added uploads/json_data_20241114_115316.xlsx
Binary file not shown.
16 changes: 16 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": 2,
"builds": [
{
"src": "main.py",
"use": "@vercel/python",
"config": { "maxLambdaSize": "15mb" }
}
],
"routes": [
{
"src": "/(.*)",
"dest": "main.py"
}
]
}

0 comments on commit 01e75eb

Please sign in to comment.