Fix: Clean syntax error in get_crypto_data_global response validation
Browse files16 unmodified lines1718192021222324252627282930313233346 unmodified lines4142434445464748495051525354555616 unmodified linesdef send_telegram(msg):if TG_TOKEN and TG_CHAT_ID:# Menggunakan Reverse Proxy publik untuk bypass block Hugging Faceproxies = [f"https://api.telegram.org/bot{TG_TOKEN}/sendMessage", # Jalur normal (tetap dicoba)f"https://teleapi.pax.workers.dev/bot{TG_TOKEN}/sendMessage", # Proxy Cloudflare 1f"https://tgproxy.nomad.workers.dev/bot{TG_TOKEN}/sendMessage" # Proxy Cloudflare 2]payload = {"chat_id": int(TG_CHAT_ID), "text": msg}for index, url in enumerate(proxies):try:# Menggunakan timeout pendek (3 detik) agar jika diblokir langsung ganti jalur proxyres = requests.post(url, json=payload, timeout=4)print(f"🤖 Telegram Route {index} Response: {res.status_code}")if res.status_code == 200:6 unmodified linesreturn "Token/Chat ID tidak dikonfigurasi"def get_crypto_data_global():try:url = "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USDT&limit=60"res = requests.get(url, timeout=5).json()if res.get("Response") == "Success" and res.get("Data") and res["Data"].get("Data"]:raw_data = res["Data"]["Data"]closes = [float(item["close"]) for item in raw_data]return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur Utama (CryptoCompare) Gagal: {str(e)}")try:url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=60&interval=daily"res = requests.get(url, timeout=5).json()16 unmodified lines17181920212223242526272829303132336 unmodified lines4041424344454647484950515253545556575816 unmodified linesdef send_telegram(msg):if TG_TOKEN and TG_CHAT_ID:# Menggunakan Reverse Proxy publik untuk bypass egress block Hugging Faceproxies = [f"https://api.telegram.org/bot{TG_TOKEN}/sendMessage",f"https://teleapi.pax.workers.dev/bot{TG_TOKEN}/sendMessage",f"https://tgproxy.nomad.workers.dev/bot{TG_TOKEN}/sendMessage"]payload = {"chat_id": int(TG_CHAT_ID), "text": msg}for index, url in enumerate(proxies):try:res = requests.post(url, json=payload, timeout=4)print(f"🤖 Telegram Route {index} Response: {res.status_code}")if res.status_code == 200:6 unmodified linesreturn "Token/Chat ID tidak dikonfigurasi"def get_crypto_data_global():# JALUR UTAMA: CryptoCompare (Sudah difix kurungnya!)try:url = "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USDT&limit=60"res = requests.get(url, timeout=5).json()if res.get("Response") == "Success" and res.get("Data") and res.get("Data").get("Data"):raw_data = res["Data"]["Data"]closes = [float(item["close"]) for item in raw_data]print("✅ Jalur Utama (CryptoCompare) Sukses Beroperasi secara Real-Time!")return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur Utama (CryptoCompare) Gagal: {str(e)}")# JALUR CADANGAN: CoinGeckotry:url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=60&interval=daily"res = requests.get(url, timeout=5).json()
app.py+8-6