68 lines
3.6 KiB
Python
68 lines
3.6 KiB
Python
|
|
#!/usr/bin/env python
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
N8N 桥接脚本 — 把 BLOG SEO 内容推送到 TG + Discord
|
|||
|
|
由 daily_auto.py 统一管线调用
|
|||
|
|
|
|||
|
|
不在 RackNerd 上跑,本地直接调 TG Bot API + Discord Webhook
|
|||
|
|
"""
|
|||
|
|
import urllib.request, json, time, random, sys, io, os
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|||
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|||
|
|
from config import TG_BOT_TOKEN as TG_BOT, DISCORD_WEBHOOK as DC_WEBHOOK, BLOG_URL as BLOG
|
|||
|
|
|
|||
|
|
TG_CHANNEL = "@GFIL_Trading"
|
|||
|
|
|
|||
|
|
def post_tg(msg):
|
|||
|
|
try:
|
|||
|
|
data = json.dumps({"chat_id": TG_CHANNEL, "text": msg, "disable_web_page_preview": False}).encode()
|
|||
|
|
req = urllib.request.Request(f"https://api.telegram.org/bot{TG_BOT}/sendMessage",
|
|||
|
|
data=data, headers={"Content-Type": "application/json"}, method="POST")
|
|||
|
|
r = urllib.request.urlopen(req, timeout=15)
|
|||
|
|
return r.status == 200
|
|||
|
|
except:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
def post_discord(msg):
|
|||
|
|
try:
|
|||
|
|
data = json.dumps({"content": msg}).encode()
|
|||
|
|
req = urllib.request.Request(DC_WEBHOOK, data=data,
|
|||
|
|
headers={"Content-Type": "application/json", "User-Agent": "Mozilla/5.0 GFIL-Bridge"}, method="POST")
|
|||
|
|
urllib.request.urlopen(req, timeout=15)
|
|||
|
|
return True
|
|||
|
|
except:
|
|||
|
|
return False
|
|||
|
|
|
|||
|
|
# ===== 推广消息池 =====
|
|||
|
|
PROMOS = [
|
|||
|
|
f"🛠 Free Position Size Calculator — (Account x Risk%) / (Stop x Pip Value) = exact lots.\n\nNo signup. No email. Just math.\n\n👉 {BLOG}/tools/position-size-calculator.html\n\n🔗 More free tools: {BLOG}/tools/",
|
|||
|
|
f"📊 16 Free Trading Calculators — no signup, no ads.\n\nPosition Size · Pip Value · Fibonacci · ATR · Kelly · Margin · R:R · Drawdown\n\nAll free → {BLOG}/tools/\n\n📱 Join: https://t.me/GFIL_Trading",
|
|||
|
|
f"🥇 Gold XAUUSD traders — stop using 50-year-old indicators.\n\nRead order flow: cumulative delta, volume profile, absorption.\n\nFull guide → {BLOG}/gold-xauusd-trading-2026.html\n\nFree tools: {BLOG}/tools/",
|
|||
|
|
f"⚡ TradingView latency: 500ms-3s. WebSocket: <50ms.\n\nDuring NFP, that's 60-100 pips/day difference for scalpers.\n\nFull data → {BLOG}/tradingview-vs-gfil-boss.html\n\nTry WebSocket speed: https://gold-node.xyz",
|
|||
|
|
f"📈 5-Minute Forex Scalping Setup:\n\nLondon open + delta divergence + 5 pip stop + 12-15 target.\n\nFull breakdown → {BLOG}/forex-scalping-2026.html\n\nFree tools: {BLOG}/tools/",
|
|||
|
|
f"🔐 Anonymous trading in 2026:\n\nBrokers see every trade. Market makers detect flow. Protect your strategy.\n\nGuide → {BLOG}/trading-activity-tracked.html\n\nPrivate terminal: https://gold-node.xyz",
|
|||
|
|
f"🧮 Kelly Criterion Calculator — the mathematically optimal bet size.\n\n40% win rate + 1:3 R:R = 20% Kelly.\n\nUse half-Kelly for safety → {BLOG}/tools/kelly-calculator.html\n\nAll tools: {BLOG}/tools/",
|
|||
|
|
f"📉 Why 87% of retail traders lose: data asymmetry.\n\nInstitutions get data 15 min before you see it.\n\nFull analysis → {BLOG}/why-retail-traders-lose-money.html\n\nClose the gap: https://gold-node.xyz",
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
ts = datetime.now().strftime("%Y-%m-%d %H:%M")
|
|||
|
|
print(f"N8N Bridge [{ts}]")
|
|||
|
|
|
|||
|
|
# Pick 2 random promos
|
|||
|
|
picks = random.sample(PROMOS, min(3, len(PROMOS)))
|
|||
|
|
tg_ok = 0
|
|||
|
|
dc_ok = 0
|
|||
|
|
|
|||
|
|
for i, msg in enumerate(picks, 1):
|
|||
|
|
print(f" [{i}/{len(picks)}] {msg[:60]}...")
|
|||
|
|
if post_tg(msg):
|
|||
|
|
tg_ok += 1
|
|||
|
|
if post_discord(msg):
|
|||
|
|
dc_ok += 1
|
|||
|
|
time.sleep(1.5)
|
|||
|
|
|
|||
|
|
print(f" Sent: TG={tg_ok}/DC={dc_ok}/{len(picks)}")
|