Spaces:
Running
Running
Upload 48 files
Browse files- content/news_scraper.py +30 -3
- scheduler/job_scheduler.py +14 -10
content/news_scraper.py
CHANGED
|
@@ -60,18 +60,45 @@ def scrape_nta_news():
|
|
| 60 |
"hash": news_hash
|
| 61 |
})
|
| 62 |
|
| 63 |
-
# Return
|
| 64 |
-
return news_items
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
logger.error(f"NTA Scraper Error: {e}")
|
| 68 |
return []
|
| 69 |
|
| 70 |
def get_news_message(item):
|
| 71 |
-
"""Format a news item for Telegram."""
|
| 72 |
return (
|
| 73 |
f"π *NEW NTA UPDATE*\n\n"
|
| 74 |
f"π {item['title']}\n\n"
|
| 75 |
f"π [Read Official Notice]({item['link']})\n\n"
|
| 76 |
f"π *CrazyLearners* | @xcrazylearners"
|
| 77 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
"hash": news_hash
|
| 61 |
})
|
| 62 |
|
| 63 |
+
# Return all new items found
|
| 64 |
+
return news_items
|
| 65 |
|
| 66 |
except Exception as e:
|
| 67 |
logger.error(f"NTA Scraper Error: {e}")
|
| 68 |
return []
|
| 69 |
|
| 70 |
def get_news_message(item):
|
| 71 |
+
"""Format a single news item for Telegram."""
|
| 72 |
return (
|
| 73 |
f"π *NEW NTA UPDATE*\n\n"
|
| 74 |
f"π {item['title']}\n\n"
|
| 75 |
f"π [Read Official Notice]({item['link']})\n\n"
|
| 76 |
f"π *CrazyLearners* | @xcrazylearners"
|
| 77 |
)
|
| 78 |
+
|
| 79 |
+
def get_consolidated_news_message(news_items):
|
| 80 |
+
"""Format multiple news items into a single consolidated message."""
|
| 81 |
+
if not news_items:
|
| 82 |
+
return ""
|
| 83 |
+
|
| 84 |
+
if len(news_items) == 1:
|
| 85 |
+
item = news_items[0]
|
| 86 |
+
return (
|
| 87 |
+
f"π *NEW NTA UPDATE*\n\n"
|
| 88 |
+
f"π *{item['title']}*\n\n"
|
| 89 |
+
f"π *Instruction:* Click the link below to view the official PDF notice.\n\n"
|
| 90 |
+
f"π [Read Official Notice (PDF)]({item['link']})\n\n"
|
| 91 |
+
f"π *CrazyLearners* | @xcrazylearners"
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
text = "π *NEW NTA UPDATES FOUND*\n"
|
| 95 |
+
text += "ββββββββββββββββββ\n\n"
|
| 96 |
+
text += "π *Instruction:* Multiple official notices were released. Select an update below to view the PDF.\n\n"
|
| 97 |
+
|
| 98 |
+
for i, item in enumerate(news_items, 1):
|
| 99 |
+
num = f"{i}οΈβ£" if i <= 10 else f"{i}."
|
| 100 |
+
text += f"{num} *{item['title']}*\n"
|
| 101 |
+
text += f"π [View Official Notice (PDF)]({item['link']})\n\n"
|
| 102 |
+
|
| 103 |
+
text += "π *CrazyLearners* | @xcrazylearners"
|
| 104 |
+
return text
|
scheduler/job_scheduler.py
CHANGED
|
@@ -224,18 +224,22 @@ async def check_nta_updates(app: Application):
|
|
| 224 |
if not news:
|
| 225 |
return
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
for item in news:
|
| 228 |
-
msg = get_news_message(item)
|
| 229 |
-
for ch_key, ch_cfg in config_manager.channels.items():
|
| 230 |
-
if ch_cfg.get("active"):
|
| 231 |
-
try:
|
| 232 |
-
await _safe_send_message(app, ch_cfg["id"], msg, parse_mode="Markdown")
|
| 233 |
-
except Exception as e:
|
| 234 |
-
logger.warning(f"Failed to post news to {ch_key}: {e}")
|
| 235 |
-
|
| 236 |
-
# Mark as seen so we don't post it again
|
| 237 |
mark_news_seen(item["hash"], item["title"])
|
| 238 |
-
|
|
|
|
| 239 |
|
| 240 |
async def reset_leaderboard_job(app: Application):
|
| 241 |
"""Post weekly winners and reset scores."""
|
|
|
|
| 224 |
if not news:
|
| 225 |
return
|
| 226 |
|
| 227 |
+
from content.news_scraper import get_consolidated_news_message
|
| 228 |
+
msg = get_consolidated_news_message(news)
|
| 229 |
+
|
| 230 |
+
# Send to all active channels
|
| 231 |
+
for ch_key, ch_cfg in config_manager.channels.items():
|
| 232 |
+
if ch_cfg.get("active"):
|
| 233 |
+
try:
|
| 234 |
+
await _safe_send_message(app, ch_cfg["id"], msg, parse_mode="Markdown")
|
| 235 |
+
except Exception as e:
|
| 236 |
+
logger.warning(f"Failed to post news bundle to {ch_key}: {e}")
|
| 237 |
+
|
| 238 |
+
# Mark all as seen
|
| 239 |
for item in news:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
mark_news_seen(item["hash"], item["title"])
|
| 241 |
+
|
| 242 |
+
logger.info(f"[Scraper] Posted consolidated alert with {len(news)} items.")
|
| 243 |
|
| 244 |
async def reset_leaderboard_job(app: Application):
|
| 245 |
"""Post weekly winners and reset scores."""
|