cybertron-spark 0.1.5__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cybertron-spark
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Automação do Zendesk com Selenium, Zenpy e integração Cybertron
5
5
  Author: Gustavo Sartorio
6
6
  Author-email: strov3rl@gmail.com
@@ -4,6 +4,8 @@ import requests
4
4
  import traceback
5
5
  import urllib3
6
6
  from dotenv import load_dotenv
7
+ import pandas as pd
8
+ import numpy as np
7
9
 
8
10
  # Desabilita avisos de certificados inseguros (opcional, conforme seu código original)
9
11
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -100,7 +102,7 @@ class Heartbeat():
100
102
  'traceback': codigo_quebrou
101
103
  }
102
104
 
103
- def registrar_ticket(self, ticket_id, pedido=None, protocolo=None, output_data=None):
105
+ def registrar_ticket(self, ticket_id=None, pedido=None, protocolo=None, output_data=None):
104
106
  endpoint = '/transformers/bots-tickets/'
105
107
 
106
108
  payload = {
@@ -113,6 +115,33 @@ class Heartbeat():
113
115
 
114
116
  return self._post(endpoint, payload)
115
117
 
118
+ def registrar_lote(self, lista_ou_df):
119
+ endpoint = '/transformers/bots-tickets/'
120
+ payload_lote = []
121
+
122
+ if hasattr(lista_ou_df, 'to_dict'):
123
+ dados_raw = lista_ou_df.to_dict(orient='records')
124
+
125
+ elif isinstance(lista_ou_df, list):
126
+ dados_raw = lista_ou_df
127
+ else:
128
+ print("❌ Erro: registrar_lote espera uma Lista ou DataFrame.")
129
+ return None
130
+
131
+ for item in dados_raw:
132
+ registro = {
133
+ 'bot_id': self.bot_id,
134
+ 'ticket_id': str(item.get('ticket_id') or item.get('service_protocol') or item.get('pedido') or item.get('order_code') or ''),
135
+ 'pedido': str(item.get('pedido') or item.get('order_code') or ''),
136
+ 'protocolo': str(item.get('protocolo') or item.get('service_protocol') or ''),
137
+ 'output_data': item
138
+ }
139
+ payload_lote.append(registro)
140
+
141
+ if payload_lote:
142
+ print(f"📤 Enviando lote de {len(payload_lote)} tickets...")
143
+ return self._post(endpoint, payload_lote)
144
+
116
145
  def atualizar_fila(self, quantidade):
117
146
  endpoint = '/transformers/bots-queue/'
118
147
 
@@ -175,4 +204,36 @@ class Heartbeat():
175
204
  'bot_realizado': True,
176
205
  }
177
206
 
178
- return self._patch(endpoint, payload)
207
+ return self._patch(endpoint, payload)
208
+
209
+ def salvar_bugiganga(self, dataframe):
210
+ endpoint = '/transformers/bots-bugigangasave/'
211
+
212
+ df_save = dataframe.copy()
213
+ colunas_data = ['abertura', 'dt_status', 'dt_cancelamento', 'ult_msg', 'dt_entrega', 'dt_prevista', 'created_at']
214
+
215
+ for col in colunas_data:
216
+ if col in df_save.columns:
217
+ df_save[col] = pd.to_datetime(df_save[col], errors='coerce').dt.strftime('%Y-%m-%dT%H:%M:%S')
218
+
219
+ df_save = df_save.replace({np.nan: None})
220
+ df_save = df_save.where(pd.notnull(df_save), None)
221
+
222
+ payload_total = df_save.to_dict(orient='records')
223
+
224
+ batch_size = 500
225
+ total_enviado = 0
226
+
227
+ print(f"📦 Iniciando envio de {len(payload_total)} registros para o banco...")
228
+
229
+ for i in range(0, len(payload_total), batch_size):
230
+ lote = payload_total[i:i + batch_size]
231
+
232
+ response = self._post(endpoint, lote)
233
+ if response and response.status_code in [200, 201]:
234
+ total_enviado += len(lote)
235
+ else:
236
+ print(f"⚠️ Falha no lote {i} a {i+batch_size}")
237
+
238
+ print(f"🏁 Finalizado. Total salvo no banco: {total_enviado}")
239
+ return total_enviado
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cybertron-spark
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Automação do Zendesk com Selenium, Zenpy e integração Cybertron
5
5
  Author: Gustavo Sartorio
6
6
  Author-email: strov3rl@gmail.com
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as arq:
5
5
 
6
6
  setup(
7
7
  name='cybertron-spark',
8
- version='0.1.5',
8
+ version='0.1.7',
9
9
  license='MIT',
10
10
  author='Gustavo Sartorio',
11
11
  author_email='strov3rl@gmail.com',
File without changes