- Adauga /scrape_solduri - scraping rapid doar solduri (fara CSV tranzactii) - Adauga /solduri - afisare instant solduri din cache (fara 2FA) - Redenumeste comenzi pentru consistenta - Adauga suport BALANCES_ONLY in scraper (skip download tranzactii) - Repara get_telegram_chat_id.py - elimina input() interactiv - Imbunatateste output get_telegram_chat_id.py cu info bot si formatare Co-Authored-By: Claude <noreply@anthropic.com>
140 lines
3.9 KiB
Python
140 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Helper script pentru obținerea Chat ID Telegram (pentru DM și grupuri)
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import requests
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment
|
|
load_dotenv()
|
|
|
|
BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
|
|
|
|
if not BOT_TOKEN:
|
|
print("=" * 60)
|
|
print("EROARE: TELEGRAM_BOT_TOKEN nu este setat în .env")
|
|
print("=" * 60)
|
|
print("\nAdaugă în .env:")
|
|
print("TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrs")
|
|
print("=" * 60)
|
|
exit(1)
|
|
|
|
def get_bot_info():
|
|
"""Preia informații despre bot"""
|
|
url = f"https://api.telegram.org/bot{BOT_TOKEN}/getMe"
|
|
response = requests.get(url)
|
|
return response.json()
|
|
|
|
def get_updates():
|
|
"""Preia ultimele update-uri de la bot"""
|
|
url = f"https://api.telegram.org/bot{BOT_TOKEN}/getUpdates"
|
|
response = requests.get(url)
|
|
return response.json()
|
|
|
|
def main():
|
|
print("=" * 60)
|
|
print(" Telegram Chat ID Helper")
|
|
print("=" * 60)
|
|
|
|
# Verifică info bot
|
|
bot_data = get_bot_info()
|
|
if bot_data.get('ok'):
|
|
bot = bot_data['result']
|
|
print(f"\nBot: @{bot.get('username')} ({bot.get('first_name')})")
|
|
print(f"Bot ID: {bot.get('id')}")
|
|
print(f"Status: ACTIV")
|
|
else:
|
|
print(f"\nERORE: Token invalid - {bot_data}")
|
|
exit(1)
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Căutare mesaje...")
|
|
print("=" * 60)
|
|
|
|
data = get_updates()
|
|
|
|
if not data.get('ok'):
|
|
print(f"\nERORE API: {data}")
|
|
return
|
|
|
|
results = data.get('result', [])
|
|
if not results:
|
|
print("\nNU S-AU GĂSIT MESAJE!")
|
|
print("\n" + "=" * 60)
|
|
print("INSTRUCȚIUNI:")
|
|
print("=" * 60)
|
|
print("1. Deschide Telegram")
|
|
print(f"2. Caută @{bot.get('username')} SAU deschide grupul cu bot-ul")
|
|
print("3. Trimite un mesaj (ex: /start sau /info)")
|
|
print("4. Rulează din nou acest script")
|
|
print("=" * 60)
|
|
return
|
|
|
|
print(f"\nGăsit {len(results)} mesaje în total")
|
|
|
|
# Procesează ultimele mesaje (ultimele 20)
|
|
seen_chats = {}
|
|
user_ids = set()
|
|
|
|
print("\n" + "=" * 60)
|
|
print("CHAT IDs DETECTATE:")
|
|
print("=" * 60)
|
|
|
|
for update in results[-20:]: # Ultimele 20 mesaje
|
|
if 'message' in update:
|
|
msg = update['message']
|
|
chat = msg['chat']
|
|
chat_id = chat['id']
|
|
chat_type = chat['type']
|
|
user = msg['from']
|
|
user_ids.add(user['id'])
|
|
text = msg.get('text', '(no text)')
|
|
|
|
# Evită duplicate
|
|
if chat_id in seen_chats:
|
|
continue
|
|
|
|
seen_chats[chat_id] = chat
|
|
|
|
# Detalii chat
|
|
if chat_type == 'private':
|
|
# DM
|
|
print(f"\n[DM] {user.get('first_name', '')} {user.get('last_name', '')}")
|
|
print(f" Username: @{user.get('username', 'N/A')}")
|
|
print(f" User ID: {user['id']}")
|
|
print(f" Chat ID: {chat_id}")
|
|
elif chat_type in ['group', 'supergroup']:
|
|
# Grup
|
|
print(f"\n[GRUP] {chat.get('title', 'Unknown')}")
|
|
print(f" Chat ID: {chat_id}")
|
|
print(f" Tip: {chat_type}")
|
|
print(f" User: @{user.get('username', 'Unknown')} (ID: {user['id']})")
|
|
|
|
print(f" Mesaj: \"{text[:60]}\"")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("CONFIGURARE .env:")
|
|
print("=" * 60)
|
|
|
|
# Recomandări
|
|
for chat_id, chat in seen_chats.items():
|
|
if chat_id < 0: # Grup
|
|
print(f"\n# Grup: {chat.get('title', 'Unknown')}")
|
|
print(f"TELEGRAM_CHAT_ID={chat_id}")
|
|
else: # DM
|
|
print(f"\n# DM")
|
|
print(f"TELEGRAM_CHAT_ID={chat_id}")
|
|
|
|
if user_ids:
|
|
user_ids_str = ",".join(str(uid) for uid in sorted(user_ids))
|
|
print(f"\n# User IDs autorizați")
|
|
print(f"TELEGRAM_ALLOWED_USER_IDS={user_ids_str}")
|
|
|
|
print("\n" + "=" * 60)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|