Spaces:
Running
Running
Tu Nombre commited on
Commit Β·
3c8f3ce
1
Parent(s): 50ad5e4
bot telegram con todos los avisos
Browse files- cliente_template.py +1 -1
- main.py +33 -1
cliente_template.py
CHANGED
|
@@ -212,7 +212,7 @@ async def pipeline():
|
|
| 212 |
proyecto_idx = CONFIG.get("proyecto_idx", -1)
|
| 213 |
if proyecto_idx >= 0:
|
| 214 |
requests.post("https://cristobal299-iaweb.hf.space/reportar-uso",
|
| 215 |
-
json={"proyecto_idx": proyecto_idx}, timeout=10)
|
| 216 |
except Exception as eu:
|
| 217 |
log(f"No se pudo reportar uso: {eu}")
|
| 218 |
except FileNotFoundError:
|
|
|
|
| 212 |
proyecto_idx = CONFIG.get("proyecto_idx", -1)
|
| 213 |
if proyecto_idx >= 0:
|
| 214 |
requests.post("https://cristobal299-iaweb.hf.space/reportar-uso",
|
| 215 |
+
json={"proyecto_idx": proyecto_idx, "email": CLIENT_EMAIL, "titulo": titulo}, timeout=10)
|
| 216 |
except Exception as eu:
|
| 217 |
log(f"No se pudo reportar uso: {eu}")
|
| 218 |
except FileNotFoundError:
|
main.py
CHANGED
|
@@ -84,6 +84,21 @@ def enviar_email(email, nicho, url):
|
|
| 84 |
|
| 85 |
CLIENTES = {}
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
def cargar_clientes():
|
| 88 |
global CLIENTES
|
| 89 |
try:
|
|
@@ -650,8 +665,20 @@ function copiar(){
|
|
| 650 |
# ββββββββββββββββββββββββββββββββββββββββββ
|
| 651 |
# RUTAS
|
| 652 |
# ββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
| 653 |
@app.get("/", response_class=HTMLResponse)
|
| 654 |
-
async def home():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
return VENTAS_HTML
|
| 656 |
|
| 657 |
PLANES_CANALES = {"basico": 1, "oro": 5, "diamante": 9, "platinum": 20}
|
|
@@ -662,6 +689,7 @@ async def activar_canal(token: str = "", plan: str = ""):
|
|
| 662 |
import secrets
|
| 663 |
nuevo_token = secrets.token_urlsafe(32)
|
| 664 |
TOKENS_VALIDOS[nuevo_token] = {"plan": plan}
|
|
|
|
| 665 |
return ACTIVAR_HTML.replace("PLAN_PLACEHOLDER", plan).replace("TOKEN_PLACEHOLDER", nuevo_token).replace("CANALES_PLACEHOLDER", str(PLANES_CANALES[plan]))
|
| 666 |
if token and token in TOKENS_VALIDOS:
|
| 667 |
plan_token = TOKENS_VALIDOS[token].get("plan", "basico") if isinstance(TOKENS_VALIDOS[token], dict) else "basico"
|
|
@@ -759,6 +787,7 @@ async def crear(request: Request):
|
|
| 759 |
CLIENTES[email]["canales"] = []
|
| 760 |
CLIENTES[email]["canales"].append({"url": u, "nicho": nicho, "tipo": tipo, "repo": repo, "youtube": False, "config": config_parsed, "config_texto": config_libre})
|
| 761 |
guardar_clientes()
|
|
|
|
| 762 |
# Consumir token si era nuevo
|
| 763 |
if token in TOKENS_VALIDOS:
|
| 764 |
del TOKENS_VALIDOS[token]
|
|
@@ -1150,8 +1179,11 @@ async def reportar_uso(request: Request):
|
|
| 1150 |
try:
|
| 1151 |
data = await request.json()
|
| 1152 |
idx = data.get("proyecto_idx", -1)
|
|
|
|
|
|
|
| 1153 |
if 0 <= idx < len(GOOGLE_PROYECTOS):
|
| 1154 |
incrementar_uso(idx)
|
|
|
|
| 1155 |
return {"ok": True, "usos_hoy": USOS_PROYECTO[idx]["count"]}
|
| 1156 |
except Exception as e:
|
| 1157 |
print(f"Error reportar uso: {e}", flush=True)
|
|
|
|
| 84 |
|
| 85 |
CLIENTES = {}
|
| 86 |
|
| 87 |
+
def avisar_telegram(mensaje):
|
| 88 |
+
"""Manda mensaje al canal de Telegram"""
|
| 89 |
+
try:
|
| 90 |
+
import requests as _r
|
| 91 |
+
token = os.environ.get("TELEGRAM_BOT_TOKEN", "")
|
| 92 |
+
chat_id = os.environ.get("TELEGRAM_CHAT_ID", "")
|
| 93 |
+
if not token or not chat_id:
|
| 94 |
+
return
|
| 95 |
+
_r.post(f"https://api.telegram.org/bot{token}/sendMessage",
|
| 96 |
+
json={"chat_id": chat_id, "text": mensaje, "parse_mode": "HTML"},
|
| 97 |
+
timeout=10
|
| 98 |
+
)
|
| 99 |
+
except Exception as e:
|
| 100 |
+
print(f"Error telegram: {e}", flush=True)
|
| 101 |
+
|
| 102 |
def cargar_clientes():
|
| 103 |
global CLIENTES
|
| 104 |
try:
|
|
|
|
| 665 |
# ββββββββββββββββββββββββββββββββββββββββββ
|
| 666 |
# RUTAS
|
| 667 |
# ββββββββββββββββββββββββββββββββββββββββββ
|
| 668 |
+
VISITAS_CACHE = {} # IP -> timestamp para no spamear avisos
|
| 669 |
+
|
| 670 |
@app.get("/", response_class=HTMLResponse)
|
| 671 |
+
async def home(request: Request):
|
| 672 |
+
try:
|
| 673 |
+
ip = request.client.host if request.client else "?"
|
| 674 |
+
import time as _t
|
| 675 |
+
ahora = _t.time()
|
| 676 |
+
# Avisar solo si esa IP no visito en los ultimos 10 min
|
| 677 |
+
if ip not in VISITAS_CACHE or ahora - VISITAS_CACHE[ip] > 600:
|
| 678 |
+
VISITAS_CACHE[ip] = ahora
|
| 679 |
+
ua = request.headers.get("user-agent","?")[:80]
|
| 680 |
+
avisar_telegram(f"π€ <b>Visita a landing</b>\nπ IP: {ip}\nπ± {ua}")
|
| 681 |
+
except: pass
|
| 682 |
return VENTAS_HTML
|
| 683 |
|
| 684 |
PLANES_CANALES = {"basico": 1, "oro": 5, "diamante": 9, "platinum": 20}
|
|
|
|
| 689 |
import secrets
|
| 690 |
nuevo_token = secrets.token_urlsafe(32)
|
| 691 |
TOKENS_VALIDOS[nuevo_token] = {"plan": plan}
|
| 692 |
+
avisar_telegram(f"π° <b>POSIBLE VENTA</b>\nπ¦ Plan: {plan.upper()}\nπ₯ Cliente llego a activar-canal tras pago Stripe")
|
| 693 |
return ACTIVAR_HTML.replace("PLAN_PLACEHOLDER", plan).replace("TOKEN_PLACEHOLDER", nuevo_token).replace("CANALES_PLACEHOLDER", str(PLANES_CANALES[plan]))
|
| 694 |
if token and token in TOKENS_VALIDOS:
|
| 695 |
plan_token = TOKENS_VALIDOS[token].get("plan", "basico") if isinstance(TOKENS_VALIDOS[token], dict) else "basico"
|
|
|
|
| 787 |
CLIENTES[email]["canales"] = []
|
| 788 |
CLIENTES[email]["canales"].append({"url": u, "nicho": nicho, "tipo": tipo, "repo": repo, "youtube": False, "config": config_parsed, "config_texto": config_libre})
|
| 789 |
guardar_clientes()
|
| 790 |
+
avisar_telegram(f"π¬ <b>Canal creado</b>\nπ§ {email}\nπΊ Plan: {plan}\nπ― Nicho: {nicho}\nπ {u}")
|
| 791 |
# Consumir token si era nuevo
|
| 792 |
if token in TOKENS_VALIDOS:
|
| 793 |
del TOKENS_VALIDOS[token]
|
|
|
|
| 1179 |
try:
|
| 1180 |
data = await request.json()
|
| 1181 |
idx = data.get("proyecto_idx", -1)
|
| 1182 |
+
email = data.get("email", "?")
|
| 1183 |
+
titulo = data.get("titulo", "?")
|
| 1184 |
if 0 <= idx < len(GOOGLE_PROYECTOS):
|
| 1185 |
incrementar_uso(idx)
|
| 1186 |
+
avisar_telegram(f"πΊ <b>Video subido a YouTube</b>\nπ§ {email}\nπ¬ {titulo[:60]}\nπ Proyecto {idx+1}: {USOS_PROYECTO[idx]['count']} videos hoy")
|
| 1187 |
return {"ok": True, "usos_hoy": USOS_PROYECTO[idx]["count"]}
|
| 1188 |
except Exception as e:
|
| 1189 |
print(f"Error reportar uso: {e}", flush=True)
|