Spaces:
Runtime error
Runtime error
Pedot commited on
Commit Β·
e585c02
1
Parent(s): 115b7a9
RM1.99, metrics guide on dashboard, top+footer buttons, Prepared by credit, subscriber perks
Browse files- bot.py +15 -7
- dashboard.py +22 -18
bot.py
CHANGED
|
@@ -203,7 +203,11 @@ async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 203 |
await update.message.reply_text(
|
| 204 |
f"β
You're already subscribed, *{username}*\\!\n\n"
|
| 205 |
"You'll receive daily reports at 6:01 AM MYT\\.\n\n"
|
| 206 |
-
"Commands:\n
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
parse_mode="MarkdownV2",
|
| 208 |
)
|
| 209 |
return
|
|
@@ -214,17 +218,21 @@ async def start_cmd(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
| 214 |
keyboard = InlineKeyboardMarkup([
|
| 215 |
[InlineKeyboardButton("π₯ Gold Report", callback_data="report_gold"),
|
| 216 |
InlineKeyboardButton("π’οΈ WTI Report", callback_data="report_wti")],
|
| 217 |
-
[InlineKeyboardButton("β Support
|
| 218 |
])
|
| 219 |
|
| 220 |
await update.message.reply_text(
|
| 221 |
f"Welcome, *{username}*\\! π\n\n"
|
| 222 |
"You're now subscribed to *Commodity Sentiment Reports*\\.\n\n"
|
| 223 |
-
"
|
| 224 |
-
"
|
| 225 |
-
"
|
| 226 |
-
"
|
| 227 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
"Tap the buttons below\\!",
|
| 229 |
parse_mode="MarkdownV2",
|
| 230 |
reply_markup=keyboard,
|
|
|
|
| 203 |
await update.message.reply_text(
|
| 204 |
f"β
You're already subscribed, *{username}*\\!\n\n"
|
| 205 |
"You'll receive daily reports at 6:01 AM MYT\\.\n\n"
|
| 206 |
+
"Commands:\n"
|
| 207 |
+
"/report β Gold report now\n"
|
| 208 |
+
"/report\\_wti β WTI report now\n"
|
| 209 |
+
"/stop β Unsubscribe\n"
|
| 210 |
+
"/status β Check status",
|
| 211 |
parse_mode="MarkdownV2",
|
| 212 |
)
|
| 213 |
return
|
|
|
|
| 218 |
keyboard = InlineKeyboardMarkup([
|
| 219 |
[InlineKeyboardButton("π₯ Gold Report", callback_data="report_gold"),
|
| 220 |
InlineKeyboardButton("π’οΈ WTI Report", callback_data="report_wti")],
|
| 221 |
+
[InlineKeyboardButton("β Support RM1.99", url=SENANGPAY_URL)],
|
| 222 |
])
|
| 223 |
|
| 224 |
await update.message.reply_text(
|
| 225 |
f"Welcome, *{username}*\\! π\n\n"
|
| 226 |
"You're now subscribed to *Commodity Sentiment Reports*\\.\n\n"
|
| 227 |
+
"π *Your Perks:*\n"
|
| 228 |
+
"π Daily Gold \\+ WTI reports at *6:01 AM MYT*\n"
|
| 229 |
+
"π On-demand /report \\| /report\\_wti anytime\n"
|
| 230 |
+
"π± Instant delivery to your phone\n\n"
|
| 231 |
+
"Commands:\n"
|
| 232 |
+
"π₯ /report β Gold report now\n"
|
| 233 |
+
"π’οΈ /report\\_wti β WTI report now\n"
|
| 234 |
+
"π« /stop β Unsubscribe\n\n"
|
| 235 |
+
"β Support us: *RM1\\.99* via SenangPay\n\n"
|
| 236 |
"Tap the buttons below\\!",
|
| 237 |
parse_mode="MarkdownV2",
|
| 238 |
reply_markup=keyboard,
|
dashboard.py
CHANGED
|
@@ -318,19 +318,8 @@ def main():
|
|
| 318 |
""", unsafe_allow_html=True)
|
| 319 |
|
| 320 |
with st.sidebar:
|
| 321 |
-
st.markdown(f"<div style='color:#86868B;font-size:13px;font-weight:600;letter-spacing:0.1em;margin-bottom:8px;font-family:{APPLE_FONT};'>
|
| 322 |
-
|
| 323 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'>Range <b>−100</b> to <b>+100</b>.<br><br><span style='color:#30D158;'>+50 to +100</span>: Extremely Bullish<br><span style='color:#34C759;'>+20 to +50</span>: Bullish<br><span style='color:#FFD60A;'>-20 to +20</span>: Neutral<br><span style='color:#FF453A;'>-50 to -20</span>: Bearish<br><span style='color:#FF3B30;'>-100 to -50</span>: Extremely Bearish<br><br><i>VADER emotional tone x keyword relevance. Articles with stronger keyword matches count more.</i></div>", unsafe_allow_html=True)
|
| 324 |
-
with st.expander("Market Mood", expanded=False):
|
| 325 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'><b>π Risk-On</b> — Market hungry for risk, bullish for commodities.<br><b>π‘οΈ Risk-Off</b> — Market fearful/defensive. Bullish for gold (safe haven), can hurt oil demand.<br><br><i>Derived from geopolitical intensity + Fed bias + sentiment.</i></div>", unsafe_allow_html=True)
|
| 326 |
-
with st.expander("DXY Bias", expanded=False):
|
| 327 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'>Tracks US Dollar Index direction.<br><br><b>Bullish Dollar</b> = commodities get cheaper ↓<br><b>Bearish Dollar</b> = commodities get pricier ↑<br><br><i>Rule: weak dollar = strong commodities.</i></div>", unsafe_allow_html=True)
|
| 328 |
-
with st.expander("Supply (WTI Only)", expanded=False):
|
| 329 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'><b>Tight</b>: Supply disruption fears (OPEC cuts, sanctions, war) — bullish.<br><b>Balanced</b>: Supply meeting demand — neutral.<br><b>Oversupply</b>: Too much oil in market — bearish.<br><br><i>Detects OPEC, EIA, inventory, production keywords.</i></div>", unsafe_allow_html=True)
|
| 330 |
-
with st.expander("VADER Score", expanded=False):
|
| 331 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'>Each article scored <b>−1.0</b> to <b>+1.0</b>:<br><br><span style='color:#30D158;'>π’ > +0.05</span>: Positive/optimistic<br><span style='color:#FFD60A;'>π‘ −0.05 to +0.05</span>: Neutral<br><span style='color:#FF453A;'>π΄ < −0.05</span>: Negative/pessimistic<br><br><i>Raw emotional tone of each headline.</i></div>", unsafe_allow_html=True)
|
| 332 |
-
with st.expander("Contrarian Alert (Gold)", expanded=False):
|
| 333 |
-
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'><b>β οΈ YES</b>: Sentiment is over-leveraged. Could reverse. Be cautious.<br><b>β
Normal</b>: Sentiment within normal bounds. No warning.<br><br><i>When everyone is bullish, who's left to buy?</i></div>", unsafe_allow_html=True)
|
| 334 |
|
| 335 |
if "commodity" not in st.session_state:
|
| 336 |
st.session_state["commodity"] = "gold"
|
|
@@ -354,6 +343,10 @@ def main():
|
|
| 354 |
st.cache_data.clear()
|
| 355 |
st.rerun()
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
result, data, price_data = fetch_and_analyze(commodity)
|
| 358 |
|
| 359 |
a1 = result["analysis_1_macro"]
|
|
@@ -436,6 +429,20 @@ def main():
|
|
| 436 |
|
| 437 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
st.markdown(f'<div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Intelligence Feed</div><div style="color:#636366;font-size:12px;font-family:{APPLE_FONT};margin-bottom:12px;">{len(data["articles"])} articles from {cm["total_articles"]} collected · {cm["rss_count"]} RSS · {cm["web_count"]} web</div>', unsafe_allow_html=True)
|
| 440 |
|
| 441 |
articles_to_show = data["articles"][:20]
|
|
@@ -459,14 +466,11 @@ def main():
|
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
-
TELEGRAM_BOT = os.environ.get("TELEGRAM_BOT_USERNAME", "SentimentIntelligence26Bot")
|
| 463 |
-
SENANGPAY_URL = os.environ.get("SENANGPAY_URL", "https://app.senangpay.my/payment/177739832230")
|
| 464 |
-
|
| 465 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 466 |
|
| 467 |
-
st.markdown(f'<div style="display:flex;align-items:center;justify-content:center;gap:20px;flex-wrap:wrap;margin-bottom:16px;"><a href="https://t.me/{TELEGRAM_BOT}" target="_blank" style="display:inline-flex;align-items:center;gap:8px;background:rgba(0,122,255,0.12);border:1px solid rgba(0,122,255,0.25);border-radius:980px;padding:12px 28px;color:#0A84FF;font-family:{APPLE_FONT};font-size:14px;font-weight:600;text-decoration:none;transition:all 0.2s ease;"><span style="font-size:18px;">βοΈ</span> Subscribe on Telegram</a><a href="{SENANGPAY_URL}" target="_blank" style="display:inline-flex;align-items:center;gap:8px;background:rgba(255,159,10,0.12);border:1px solid rgba(255,159,10,0.25);border-radius:980px;padding:12px 28px;color:#FF9F0A;font-family:{APPLE_FONT};font-size:14px;font-weight:600;text-decoration:none;transition:all 0.2s ease;"><span style="font-size:18px;">β</span> Support for
|
| 468 |
|
| 469 |
-
st.markdown(f'<div style="text-align:center;color:#636366;font-size:11px;font-family:{APPLE_FONT};margin-bottom:20px;">Daily reports at 6:01 AM MYT · /report /report\\_wti for on-demand · VADER + Rule-Based Engine</div>', unsafe_allow_html=True)
|
| 470 |
|
| 471 |
try:
|
| 472 |
from streamlit_autorefresh import st_autorefresh
|
|
|
|
| 318 |
""", unsafe_allow_html=True)
|
| 319 |
|
| 320 |
with st.sidebar:
|
| 321 |
+
st.markdown(f"<div style='color:#86868B;font-size:13px;font-weight:600;letter-spacing:0.1em;margin-bottom:8px;font-family:{APPLE_FONT};'>ABOUT</div>", unsafe_allow_html=True)
|
| 322 |
+
st.markdown(f"<div style='color:#86868B;font-size:12px;line-height:1.6;font-family:{APPLE_FONT};'>Real-time sentiment intelligence for Gold & WTI Crude Oil.<br><br>VADER NLP + Rule-Based engine scanning RSS feeds and news articles.<br><br>Daily Telegram report at <b>6:01 AM MYT</b>.<br><br><a href='https://t.me/PedotTTRG' style='color:#0A84FF;'>Prepared by @PedotTTRG</a></div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
|
| 324 |
if "commodity" not in st.session_state:
|
| 325 |
st.session_state["commodity"] = "gold"
|
|
|
|
| 343 |
st.cache_data.clear()
|
| 344 |
st.rerun()
|
| 345 |
|
| 346 |
+
TELEGRAM_BOT = os.environ.get("TELEGRAM_BOT_USERNAME", "SentimentIntelligence26Bot")
|
| 347 |
+
SENANGPAY_URL = os.environ.get("SENANGPAY_URL", "https://app.senangpay.my/payment/177739832230")
|
| 348 |
+
st.markdown(f'<div style="display:flex;align-items:center;justify-content:center;gap:12px;flex-wrap:wrap;margin-bottom:20px;"><a href="https://t.me/{TELEGRAM_BOT}" target="_blank" style="display:inline-flex;align-items:center;gap:6px;background:rgba(0,122,255,0.15);border:1px solid rgba(0,122,255,0.3);border-radius:980px;padding:10px 22px;color:#0A84FF;font-family:{APPLE_FONT};font-size:13px;font-weight:600;text-decoration:none;"><span style="font-size:16px;">βοΈ</span> Subscribe on Telegram</a><a href="{SENANGPAY_URL}" target="_blank" style="display:inline-flex;align-items:center;gap:6px;background:rgba(255,159,10,0.15);border:1px solid rgba(255,159,10,0.3);border-radius:980px;padding:10px 22px;color:#FF9F0A;font-family:{APPLE_FONT};font-size:13px;font-weight:600;text-decoration:none;"><span style="font-size:16px;">β</span> Support for RM1.99</a></div>', unsafe_allow_html=True)
|
| 349 |
+
|
| 350 |
result, data, price_data = fetch_and_analyze(commodity)
|
| 351 |
|
| 352 |
a1 = result["analysis_1_macro"]
|
|
|
|
| 429 |
|
| 430 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 431 |
|
| 432 |
+
st.markdown(f"<div style='color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:12px;'>How to Read</div>", unsafe_allow_html=True)
|
| 433 |
+
g1, g2, g3 = st.columns(3)
|
| 434 |
+
with g1:
|
| 435 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>Sentiment Score</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>Range −100 to +100.<br><span style='color:#30D158;'>+50/+100</span> Bullish · <span style='color:#FF453A;'>−50/−100</span> Bearish<br><span style='color:#FFD60A;'>-20/+20</span> Neutral<br><i>VADER x keyword weight</i></div></div>", unsafe_allow_html=True)
|
| 436 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>DXY Bias</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>US Dollar direction.<br>Weak dollar = commodities go up<br>Strong dollar = commodities go down</div></div>", unsafe_allow_html=True)
|
| 437 |
+
with g2:
|
| 438 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>Market Mood</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>π Risk-On = bullish for commodities<br>π‘οΈ Risk-Off = safe haven (gold up, oil demand down)</div></div>", unsafe_allow_html=True)
|
| 439 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>Contrarian Alert</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>β οΈ YES = sentiment over-leveraged, reversal possible<br>β
Normal = within safe range</div></div>", unsafe_allow_html=True)
|
| 440 |
+
with g3:
|
| 441 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>VADER (per article)</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>π’ > +0.05 positive article<br>π‘ −0.05 to +0.05 neutral<br>π΄ < −0.05 negative article</div></div>", unsafe_allow_html=True)
|
| 442 |
+
st.markdown(f"<div style='background:rgba(28,28,30,0.5);border:1px solid rgba(255,255,255,0.06);border-radius:16px;padding:16px 20px;margin-bottom:6px;'><div style='color:#F5F5F7;font-size:13px;font-weight:600;font-family:{APPLE_FONT};margin-bottom:6px;'>Supply (WTI Only)</div><div style='color:#86868B;font-size:11px;line-height:1.5;font-family:{APPLE_FONT};'>Tight = bullish (OPEC cuts, war)<br>Balanced = neutral<br>Oversupply = bearish</div></div>", unsafe_allow_html=True)
|
| 443 |
+
|
| 444 |
+
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 445 |
+
|
| 446 |
st.markdown(f'<div style="color:#86868B;font-size:11px;font-weight:600;letter-spacing:0.1em;text-transform:uppercase;font-family:{APPLE_FONT};margin-bottom:16px;">Intelligence Feed</div><div style="color:#636366;font-size:12px;font-family:{APPLE_FONT};margin-bottom:12px;">{len(data["articles"])} articles from {cm["total_articles"]} collected · {cm["rss_count"]} RSS · {cm["web_count"]} web</div>', unsafe_allow_html=True)
|
| 447 |
|
| 448 |
articles_to_show = data["articles"][:20]
|
|
|
|
| 466 |
|
| 467 |
|
| 468 |
|
|
|
|
|
|
|
|
|
|
| 469 |
st.markdown("<div style='border-top: 1px solid rgba(255,255,255,0.06); margin: 28px 0;'></div>", unsafe_allow_html=True)
|
| 470 |
|
| 471 |
+
st.markdown(f'<div style="display:flex;align-items:center;justify-content:center;gap:20px;flex-wrap:wrap;margin-bottom:16px;"><a href="https://t.me/{TELEGRAM_BOT}" target="_blank" style="display:inline-flex;align-items:center;gap:8px;background:rgba(0,122,255,0.12);border:1px solid rgba(0,122,255,0.25);border-radius:980px;padding:12px 28px;color:#0A84FF;font-family:{APPLE_FONT};font-size:14px;font-weight:600;text-decoration:none;transition:all 0.2s ease;"><span style="font-size:18px;">βοΈ</span> Subscribe on Telegram</a><a href="{SENANGPAY_URL}" target="_blank" style="display:inline-flex;align-items:center;gap:8px;background:rgba(255,159,10,0.12);border:1px solid rgba(255,159,10,0.25);border-radius:980px;padding:12px 28px;color:#FF9F0A;font-family:{APPLE_FONT};font-size:14px;font-weight:600;text-decoration:none;transition:all 0.2s ease;"><span style="font-size:18px;">β</span> Support for RM1.99</a></div>', unsafe_allow_html=True)
|
| 472 |
|
| 473 |
+
st.markdown(f'<div style="text-align:center;color:#636366;font-size:11px;font-family:{APPLE_FONT};margin-bottom:20px;">Daily reports at 6:01 AM MYT · /report /report\\_wti for on-demand · VADER + Rule-Based Engine<br><br><span style="color:#86868B;">Prepared by</span> <a href="https://t.me/PedotTTRG" target="_blank" style="color:#0A84FF;text-decoration:none;">@PedotTTRG</a></div>', unsafe_allow_html=True)
|
| 474 |
|
| 475 |
try:
|
| 476 |
from streamlit_autorefresh import st_autorefresh
|