-
Notifications
You must be signed in to change notification settings - Fork 351
Description
import requests
import time
====== 你的 Bot Token & User ID ======
BOT_TOKEN = "在這裡填入你的完整 Token"
CHAT_ID = "在這裡填入你的 Telegram User ID"
====== 發送訊息到 Telegram ======
def send(msg):
url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
data = {"chat_id": CHAT_ID, "text": msg}
requests.post(url, data=data)
====== SofaScore API 抓取 ======
def get_live_data(match_id):
url = f"https://api.sofascore.com/api/v1/event/{match_id}/statistics"
r = requests.get(url).json()
stats = r["statistics"][0]["groups"]
data = {
"shots": stats[0]["statisticsItems"][0]["home"],
"shots_on": stats[0]["statisticsItems"][1]["home"],
"dangerous_attacks": stats[2]["statisticsItems"][2]["home"],
"corners": stats[1]["statisticsItems"][2]["home"],
"xg_total": stats[3]["statisticsItems"][0]["home"],
"wing_attack_ratio": 42, # SofaScore 無此數據 → 固定值
"odds_before": 2.40,
"odds_now": 2.20,
"xg_change": 0.28,
"team": "大阪飛腳",
"line": 2.5,
"corner_line": 8.5
}
return data
====== AI 模組 ======
def goal_signal(d):
return (
d["dangerous_attacks"] > 60 and
d["xg_change"] >= 0.25 and
abs(d["odds_before"] - d["odds_now"]) / d["odds_before"] >= 0.08
)
def over_signal(d):
score = 0
if d["xg_total"] >= 1.0: score += 1
if d["dangerous_attacks"] > 65: score += 1
if d["shots"] >= 10: score += 1
if d["corners"] >= 6: score += 1
return score >= 3
def corner_signal(d):
score = 0
if d["dangerous_attacks"] > 60: score += 1
if d["shots"] >= 8: score += 1
if d["wing_attack_ratio"] >= 40: score += 1
return score >= 3
====== 主迴圈 ======
MATCH_ID = 123456 # 你要監控的比賽 ID
while True:
d = get_live_data(MATCH_ID)
if goal_signal(d):
send(f"⚠️【進球前兆】\n隊伍:{d['team']}\n危險進攻:{d['dangerous_attacks']}%\nxG:+{d['xg_change']}\n賠率急跌:{d['odds_before']} → {d['odds_now']}\n建議:買「{d['team']} 下一個進球」")
if over_signal(d):
send(f"📈【大球訊號】\n射門:{d['shots']}\nxG:{d['xg_total']}\n危險進攻:{d['dangerous_attacks']}%\n建議:買大球 Over {d['line']}")
if corner_signal(d):
send(f"🚩【角球大】\n角球:{d['corners']}\n危險進攻:{d['dangerous_attacks']}%\n邊路進攻:{d['wing_attack_ratio']}%\n建議:買大角 Over {d['corner_line']}")
time.sleep(5)