habulaj commited on
Commit
bc10bb3
·
verified ·
1 Parent(s): c53a7af

Update routes/dashboard_home.py

Browse files
Files changed (1) hide show
  1. routes/dashboard_home.py +10 -3
routes/dashboard_home.py CHANGED
@@ -314,14 +314,21 @@ async def get_top_stylists(start_timestamp: Optional[int] = None, end_timestamp:
314
  # Obter detalhes dos estilistas em uma única chamada
315
  stylists_url = f"{SUPABASE_URL}/rest/v1/User?id=in.({','.join(top_stylist_ids)})&select=id,name,avatar"
316
 
 
 
 
 
317
  # Obter detalhes dos estilistas
318
  async with aiohttp.ClientSession() as session:
319
- async with session.get(stylists_url, headers=SUPABASE_HEADERS) as response:
320
  if response.status != 200:
321
  logger.error(f"❌ Erro ao obter detalhes dos estilistas: {response.status}")
322
  return []
323
 
324
- stylists_data = await response.json()
 
 
 
325
 
326
  # Mapear os IDs para facilitar o acesso
327
  stylists_map = {stylist["id"]: stylist for stylist in stylists_data}
@@ -343,7 +350,7 @@ async def get_top_stylists(start_timestamp: Optional[int] = None, end_timestamp:
343
  except Exception as e:
344
  logger.error(f"❌ Erro ao obter top estilistas: {str(e)}")
345
  return []
346
-
347
  async def get_monthly_revenue_data(target_date) -> Dict[str, Any]:
348
  """Obtém o faturamento de um mês específico de forma otimizada"""
349
  ny_timezone = pytz.timezone('America/New_York')
 
314
  # Obter detalhes dos estilistas em uma única chamada
315
  stylists_url = f"{SUPABASE_URL}/rest/v1/User?id=in.({','.join(top_stylist_ids)})&select=id,name,avatar"
316
 
317
+ # Modificar os headers para garantir que a resposta seja tratada como UTF-8
318
+ headers = SUPABASE_HEADERS.copy()
319
+ headers["Accept"] = "application/json; charset=utf-8"
320
+
321
  # Obter detalhes dos estilistas
322
  async with aiohttp.ClientSession() as session:
323
+ async with session.get(stylists_url, headers=headers) as response:
324
  if response.status != 200:
325
  logger.error(f"❌ Erro ao obter detalhes dos estilistas: {response.status}")
326
  return []
327
 
328
+ # Forçar a decodificação como UTF-8
329
+ text = await response.text(encoding='utf-8')
330
+ import json
331
+ stylists_data = json.loads(text)
332
 
333
  # Mapear os IDs para facilitar o acesso
334
  stylists_map = {stylist["id"]: stylist for stylist in stylists_data}
 
350
  except Exception as e:
351
  logger.error(f"❌ Erro ao obter top estilistas: {str(e)}")
352
  return []
353
+
354
  async def get_monthly_revenue_data(target_date) -> Dict[str, Any]:
355
  """Obtém o faturamento de um mês específico de forma otimizada"""
356
  ny_timezone = pytz.timezone('America/New_York')