Spaces:
Sleeping
Sleeping
Tokens received by registrar_evento
Browse files- herramientas.py +9 -15
- main.py +1 -1
herramientas.py
CHANGED
|
@@ -23,36 +23,25 @@ def imprimeTime():
|
|
| 23 |
|
| 24 |
return formatted_time
|
| 25 |
|
| 26 |
-
def registrar_evento(cus: str):
|
| 27 |
"""
|
| 28 |
-
|
| 29 |
-
en un archivo 'registro.txt' en la raíz del proyecto.
|
| 30 |
|
| 31 |
Args:
|
| 32 |
-
|
| 33 |
"""
|
| 34 |
# 1. Obtener la fecha y hora actual en el formato deseado
|
| 35 |
-
fecha = imprimeTime() # Utiliza tu función existente
|
| 36 |
-
|
| 37 |
# 2. Definir el nombre del archivo de registro
|
| 38 |
#file_name = "registro.txt"
|
| 39 |
-
|
| 40 |
# 3. Obtener la ruta completa al archivo en la raíz del proyecto
|
| 41 |
# Esto asume que el script que llama a esta función está en la raíz.
|
| 42 |
# script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 43 |
# registro_path = os.path.join(script_dir, file_name)
|
| 44 |
-
|
| 45 |
# 4. Formatear la línea que se guardará en el archivo
|
| 46 |
# Puedes elegir el formato que prefieras. Un buen formato sería CSV o algo legible.
|
| 47 |
# Por ejemplo: "FECHA_HORA,TIPO_DE_EVENTO\n"
|
| 48 |
#log_line = f"{fecha},{cus}\n"
|
| 49 |
-
|
| 50 |
-
resultado = fireWhale.encontrar_documento_por_cus(cus)
|
| 51 |
-
print("Ésto es el resultado de buscar el cus:")
|
| 52 |
-
print(resultado)
|
| 53 |
-
|
| 54 |
-
fireWhale.editaDato('usuarios', resultado, 'tokens', 182)
|
| 55 |
-
|
| 56 |
# 5. Abrir el archivo en modo de añadir ('a') y escribir la línea
|
| 57 |
# try:
|
| 58 |
# with open(registro_path, 'a') as f:
|
|
@@ -60,3 +49,8 @@ def registrar_evento(cus: str):
|
|
| 60 |
# print(f"[{fecha}] Evento '{event_type}' registrado con éxito en '{registro_path}'")
|
| 61 |
# except Exception as e:
|
| 62 |
# print(f"Error al escribir en el archivo de registro '{registro_path}': {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
return formatted_time
|
| 25 |
|
| 26 |
+
def registrar_evento(cus: str, tokens: int):
|
| 27 |
"""
|
| 28 |
+
Registra los tokens correspondientes a la compra realizada por el usuario.
|
|
|
|
| 29 |
|
| 30 |
Args:
|
| 31 |
+
cus (str): customer de stripe.
|
| 32 |
"""
|
| 33 |
# 1. Obtener la fecha y hora actual en el formato deseado
|
| 34 |
+
#fecha = imprimeTime() # Utiliza tu función existente
|
|
|
|
| 35 |
# 2. Definir el nombre del archivo de registro
|
| 36 |
#file_name = "registro.txt"
|
|
|
|
| 37 |
# 3. Obtener la ruta completa al archivo en la raíz del proyecto
|
| 38 |
# Esto asume que el script que llama a esta función está en la raíz.
|
| 39 |
# script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 40 |
# registro_path = os.path.join(script_dir, file_name)
|
|
|
|
| 41 |
# 4. Formatear la línea que se guardará en el archivo
|
| 42 |
# Puedes elegir el formato que prefieras. Un buen formato sería CSV o algo legible.
|
| 43 |
# Por ejemplo: "FECHA_HORA,TIPO_DE_EVENTO\n"
|
| 44 |
#log_line = f"{fecha},{cus}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# 5. Abrir el archivo en modo de añadir ('a') y escribir la línea
|
| 46 |
# try:
|
| 47 |
# with open(registro_path, 'a') as f:
|
|
|
|
| 49 |
# print(f"[{fecha}] Evento '{event_type}' registrado con éxito en '{registro_path}'")
|
| 50 |
# except Exception as e:
|
| 51 |
# print(f"Error al escribir en el archivo de registro '{registro_path}': {e}")
|
| 52 |
+
|
| 53 |
+
resultado = fireWhale.encontrar_documento_por_cus(cus)
|
| 54 |
+
# print("Ésto es el resultado de buscar el cus:")
|
| 55 |
+
# print(resultado)
|
| 56 |
+
fireWhale.editaDato('usuarios', resultado, 'tokens', tokens)
|
main.py
CHANGED
|
@@ -57,7 +57,7 @@ async def webhook_received(request: Request, stripe_signature: str = Header(None
|
|
| 57 |
print("Customer:")
|
| 58 |
cus = event_data['customer']
|
| 59 |
print(cus)
|
| 60 |
-
herramientas.registrar_evento(cus)
|
| 61 |
|
| 62 |
else:
|
| 63 |
print(f'unhandled event: {event_type}')
|
|
|
|
| 57 |
print("Customer:")
|
| 58 |
cus = event_data['customer']
|
| 59 |
print(cus)
|
| 60 |
+
herramientas.registrar_evento(cus, 999)
|
| 61 |
|
| 62 |
else:
|
| 63 |
print(f'unhandled event: {event_type}')
|