Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,737 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import re
|
| 3 |
-
import json
|
| 4 |
-
import time
|
| 5 |
-
import random
|
| 6 |
-
import logging
|
| 7 |
-
import asyncio
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
from typing import Dict, List, Optional, Any, Tuple
|
| 11 |
-
|
| 12 |
-
import pytz
|
| 13 |
-
import requests
|
| 14 |
-
import feedparser
|
| 15 |
-
import google.generativeai as genai
|
| 16 |
-
from bs4 import BeautifulSoup
|
| 17 |
-
from apscheduler.schedulers.background import BackgroundScheduler
|
| 18 |
-
from telegram import Bot
|
| 19 |
-
from telegram.error import TelegramError
|
| 20 |
-
from pyrogram import Client
|
| 21 |
-
from flask import Flask
|
| 22 |
-
|
| 23 |
-
# =========================
|
| 24 |
-
# Castle Info Bot
|
| 25 |
-
# Telegram + RSS + Gemini
|
| 26 |
-
# Auto Gemini model discovery
|
| 27 |
-
# =========================
|
| 28 |
-
|
| 29 |
-
logging.basicConfig(
|
| 30 |
-
level=logging.INFO,
|
| 31 |
-
format="%(asctime)s | %(levelname)s | %(message)s"
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
BOT_TOKEN = os.getenv("BOT_TOKEN", "").strip()
|
| 35 |
-
API_ID = int(os.getenv("API_ID", "0") or "0")
|
| 36 |
-
API_HASH = os.getenv("API_HASH", "").strip()
|
| 37 |
-
TELEGRAM_CHANNEL_ID = os.getenv("TELEGRAM_CHANNEL_ID", "").strip()
|
| 38 |
-
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "").strip()
|
| 39 |
-
|
| 40 |
-
TIMEZONE = os.getenv("TIMEZONE", "Asia/Baghdad").strip()
|
| 41 |
-
RUN_ON_START = os.getenv("RUN_ON_START", "false").lower() == "true"
|
| 42 |
-
|
| 43 |
-
# Optional. If you set GEMINI_MODEL in Secrets, bot tries it first.
|
| 44 |
-
# If empty, bot auto-discovers available models.
|
| 45 |
-
PREFERRED_GEMINI_MODEL = os.getenv("GEMINI_MODEL", "").strip()
|
| 46 |
-
|
| 47 |
-
POST_HOURS = [10, 12, 14, 16, 18, 20, 22]
|
| 48 |
-
|
| 49 |
-
SIGNATURE = "لأنك تستحق أن تعرف | #قلعة_المعلومات_العامة | اشتـــرك الآن :- https://t.me/CastleInfoiq"
|
| 50 |
-
|
| 51 |
-
DATA_DIR = Path(os.getenv("DATA_DIR", "."))
|
| 52 |
-
DATA_FILE = DATA_DIR / "data.json"
|
| 53 |
-
BACKUP_FILE = DATA_DIR / "data.backup.json"
|
| 54 |
-
|
| 55 |
-
USER_AGENT = (
|
| 56 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
| 57 |
-
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
| 58 |
-
"Chrome/125.0 Safari/537.36"
|
| 59 |
-
)
|
| 60 |
-
|
| 61 |
-
RSS_SOURCES = [
|
| 62 |
-
{
|
| 63 |
-
"name": "NASA",
|
| 64 |
-
"category": "فضاء",
|
| 65 |
-
"url": "https://www.nasa.gov/rss/dyn/breaking_news.rss",
|
| 66 |
-
"hashtags": "#فضاء #ناسا #الكون #معلومات_عامة"
|
| 67 |
-
},
|
| 68 |
-
{
|
| 69 |
-
"name": "NASA Science",
|
| 70 |
-
"category": "فضاء",
|
| 71 |
-
"url": "https://science.nasa.gov/feed/",
|
| 72 |
-
"hashtags": "#فضاء #علوم #الكون #معلومات_عامة"
|
| 73 |
-
},
|
| 74 |
-
{
|
| 75 |
-
"name": "ScienceDaily",
|
| 76 |
-
"category": "علوم",
|
| 77 |
-
"url": "https://www.sciencedaily.com/rss/top.xml",
|
| 78 |
-
"hashtags": "#علوم #اكتشافات #معرفة #معلومات_عامة"
|
| 79 |
-
},
|
| 80 |
-
{
|
| 81 |
-
"name": "ScienceDaily Space",
|
| 82 |
-
"category": "فضاء",
|
| 83 |
-
"url": "https://www.sciencedaily.com/rss/space_time.xml",
|
| 84 |
-
"hashtags": "#فضاء #علوم #الكون #معلومات_عامة"
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"name": "ScienceDaily Matter",
|
| 88 |
-
"category": "علوم",
|
| 89 |
-
"url": "https://www.sciencedaily.com/rss/matter_energy.xml",
|
| 90 |
-
"hashtags": "#علوم #اكتشافات #تكنولوجيا #معلومات_عامة"
|
| 91 |
-
},
|
| 92 |
-
{
|
| 93 |
-
"name": "World History Encyclopedia",
|
| 94 |
-
"category": "تاريخ",
|
| 95 |
-
"url": "https://www.worldhistory.org/rss/",
|
| 96 |
-
"hashtags": "#تاريخ #حضارات #معرفة #معلومات_عامة"
|
| 97 |
-
}
|
| 98 |
-
]
|
| 99 |
-
|
| 100 |
-
FALLBACK_TOPICS = [
|
| 101 |
-
"قصة بناء الأهرامات وأسرارها العلمية",
|
| 102 |
-
"كيف غيّر نيوتن فهم البشر للكون",
|
| 103 |
-
"أغرب أسرار كوكب المشتري",
|
| 104 |
-
"قصة مكتبة الإسكندرية ولماذا بقيت لغزاً",
|
| 105 |
-
"كيف بدأت الثورة الصناعية وغيرت العالم",
|
| 106 |
-
"العلماء الذين غيروا مجرى التاريخ",
|
| 107 |
-
"أسرار الثقوب السوداء بطريقة مبسطة",
|
| 108 |
-
"حضارة وادي الرافدين وأثرها على العالم",
|
| 109 |
-
"كيف تعمل الذاكرة داخل دماغ الإنسان",
|
| 110 |
-
"اختراعات ظهرت بالصدفة وغيرت حياتنا",
|
| 111 |
-
"لماذا كان اكتشاف الكهرباء نقطة تحول في التاريخ",
|
| 112 |
-
"كيف عرف الإنسان الزمن قبل اختراع الساعة"
|
| 113 |
-
]
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
def validate_env() -> None:
|
| 117 |
-
missing = []
|
| 118 |
-
if not BOT_TOKEN:
|
| 119 |
-
missing.append("BOT_TOKEN")
|
| 120 |
-
if not TELEGRAM_CHANNEL_ID:
|
| 121 |
-
missing.append("TELEGRAM_CHANNEL_ID")
|
| 122 |
-
if not GOOGLE_API_KEY:
|
| 123 |
-
missing.append("GOOGLE_API_KEY")
|
| 124 |
-
if missing:
|
| 125 |
-
raise RuntimeError("Missing secrets: " + ", ".join(missing))
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
def load_data() -> Dict[str, Any]:
|
| 129 |
-
default = {
|
| 130 |
-
"posted_links": [],
|
| 131 |
-
"posted_titles": [],
|
| 132 |
-
"last_posts": [],
|
| 133 |
-
"last_error": "",
|
| 134 |
-
"active_gemini_model": "",
|
| 135 |
-
"created_at": datetime.utcnow().isoformat()
|
| 136 |
-
}
|
| 137 |
-
|
| 138 |
-
if not DATA_FILE.exists():
|
| 139 |
-
save_data(default)
|
| 140 |
-
return default
|
| 141 |
-
|
| 142 |
-
try:
|
| 143 |
-
data = json.loads(DATA_FILE.read_text(encoding="utf-8"))
|
| 144 |
-
if not isinstance(data, dict):
|
| 145 |
-
raise ValueError("data.json is not a JSON object")
|
| 146 |
-
for k, v in default.items():
|
| 147 |
-
data.setdefault(k, v)
|
| 148 |
-
return data
|
| 149 |
-
except Exception as e:
|
| 150 |
-
logging.error("data.json corrupted, trying backup: %s", e)
|
| 151 |
-
if BACKUP_FILE.exists():
|
| 152 |
-
try:
|
| 153 |
-
data = json.loads(BACKUP_FILE.read_text(encoding="utf-8"))
|
| 154 |
-
if isinstance(data, dict):
|
| 155 |
-
for k, v in default.items():
|
| 156 |
-
data.setdefault(k, v)
|
| 157 |
-
save_data(data)
|
| 158 |
-
return data
|
| 159 |
-
except Exception as e2:
|
| 160 |
-
logging.error("backup restore failed: %s", e2)
|
| 161 |
-
|
| 162 |
-
save_data(default)
|
| 163 |
-
return default
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
def save_data(data: Dict[str, Any]) -> None:
|
| 167 |
-
try:
|
| 168 |
-
if DATA_FILE.exists() and DATA_FILE.stat().st_size > 5:
|
| 169 |
-
BACKUP_FILE.write_text(DATA_FILE.read_text(encoding="utf-8"), encoding="utf-8")
|
| 170 |
-
except Exception:
|
| 171 |
-
pass
|
| 172 |
-
|
| 173 |
-
tmp = DATA_FILE.with_suffix(".tmp")
|
| 174 |
-
tmp.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 175 |
-
tmp.replace(DATA_FILE)
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
def normalize_text(text: str) -> str:
|
| 179 |
-
text = BeautifulSoup(text or "", "html.parser").get_text(" ", strip=True)
|
| 180 |
-
text = re.sub(r"\s+", " ", text).strip()
|
| 181 |
-
return text
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
def clean_title(title: str) -> str:
|
| 185 |
-
return normalize_text(title)[:180]
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
def fetch_url(url: str, timeout: int = 20) -> Optional[str]:
|
| 189 |
-
try:
|
| 190 |
-
r = requests.get(
|
| 191 |
-
url,
|
| 192 |
-
headers={"User-Agent": USER_AGENT, "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
|
| 193 |
-
timeout=timeout,
|
| 194 |
-
allow_redirects=True
|
| 195 |
-
)
|
| 196 |
-
if r.status_code == 200 and r.text:
|
| 197 |
-
return r.text
|
| 198 |
-
logging.warning("fetch failed %s status=%s", url, r.status_code)
|
| 199 |
-
except Exception as e:
|
| 200 |
-
logging.warning("fetch exception %s | %s", url, e)
|
| 201 |
-
return None
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
def extract_image_from_entry(entry: Any, article_url: str = "") -> Optional[str]:
|
| 205 |
-
candidates = []
|
| 206 |
-
|
| 207 |
-
try:
|
| 208 |
-
for m in getattr(entry, "media_content", []) or []:
|
| 209 |
-
if m.get("url"):
|
| 210 |
-
candidates.append(m.get("url"))
|
| 211 |
-
except Exception:
|
| 212 |
-
pass
|
| 213 |
-
|
| 214 |
-
try:
|
| 215 |
-
for m in getattr(entry, "media_thumbnail", []) or []:
|
| 216 |
-
if m.get("url"):
|
| 217 |
-
candidates.append(m.get("url"))
|
| 218 |
-
except Exception:
|
| 219 |
-
pass
|
| 220 |
-
|
| 221 |
-
for key in ["image", "thumbnail"]:
|
| 222 |
-
try:
|
| 223 |
-
val = entry.get(key)
|
| 224 |
-
if val:
|
| 225 |
-
candidates.append(val)
|
| 226 |
-
except Exception:
|
| 227 |
-
pass
|
| 228 |
-
|
| 229 |
-
try:
|
| 230 |
-
summary = entry.get("summary", "") or entry.get("description", "")
|
| 231 |
-
soup = BeautifulSoup(summary, "html.parser")
|
| 232 |
-
img = soup.find("img")
|
| 233 |
-
if img and img.get("src"):
|
| 234 |
-
candidates.append(img.get("src"))
|
| 235 |
-
except Exception:
|
| 236 |
-
pass
|
| 237 |
-
|
| 238 |
-
if article_url:
|
| 239 |
-
html = fetch_url(article_url, timeout=12)
|
| 240 |
-
if html:
|
| 241 |
-
soup = BeautifulSoup(html, "html.parser")
|
| 242 |
-
for attr, value in [
|
| 243 |
-
("property", "og:image"),
|
| 244 |
-
("name", "twitter:image"),
|
| 245 |
-
("property", "twitter:image")
|
| 246 |
-
]:
|
| 247 |
-
tag = soup.find("meta", attrs={attr: value})
|
| 248 |
-
if tag and tag.get("content"):
|
| 249 |
-
candidates.append(tag.get("content"))
|
| 250 |
-
|
| 251 |
-
for c in candidates:
|
| 252 |
-
if isinstance(c, str) and c.startswith("http"):
|
| 253 |
-
return c
|
| 254 |
-
return None
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
def extract_article_text(entry: Any, url: str) -> str:
|
| 258 |
-
parts = []
|
| 259 |
-
|
| 260 |
-
for key in ["title", "summary", "description"]:
|
| 261 |
-
try:
|
| 262 |
-
val = entry.get(key, "")
|
| 263 |
-
if val:
|
| 264 |
-
parts.append(normalize_text(val))
|
| 265 |
-
except Exception:
|
| 266 |
-
pass
|
| 267 |
-
|
| 268 |
-
html = fetch_url(url, timeout=15)
|
| 269 |
-
if html:
|
| 270 |
-
soup = BeautifulSoup(html, "html.parser")
|
| 271 |
-
for bad in soup(["script", "style", "noscript", "header", "footer", "nav", "aside"]):
|
| 272 |
-
bad.decompose()
|
| 273 |
-
|
| 274 |
-
article = soup.find("article") or soup.find("main") or soup.body
|
| 275 |
-
if article:
|
| 276 |
-
paragraphs = [normalize_text(p.get_text(" ", strip=True)) for p in article.find_all("p")]
|
| 277 |
-
paragraphs = [p for p in paragraphs if len(p) > 45]
|
| 278 |
-
if paragraphs:
|
| 279 |
-
parts.append(" ".join(paragraphs[:9]))
|
| 280 |
-
|
| 281 |
-
text = normalize_text(" ".join(parts))
|
| 282 |
-
return text[:6000]
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
def get_candidate_article(data: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
| 286 |
-
sources = RSS_SOURCES[:]
|
| 287 |
-
random.shuffle(sources)
|
| 288 |
-
|
| 289 |
-
posted_links = set(data.get("posted_links", []))
|
| 290 |
-
posted_titles = set(data.get("posted_titles", []))
|
| 291 |
-
|
| 292 |
-
for source in sources:
|
| 293 |
-
try:
|
| 294 |
-
logging.info("Checking RSS: %s", source["name"])
|
| 295 |
-
feed = feedparser.parse(source["url"])
|
| 296 |
-
entries = list(feed.entries or [])
|
| 297 |
-
except Exception as e:
|
| 298 |
-
logging.warning("RSS parse failed %s | %s", source["name"], e)
|
| 299 |
-
continue
|
| 300 |
-
|
| 301 |
-
random.shuffle(entries)
|
| 302 |
-
|
| 303 |
-
for entry in entries[:14]:
|
| 304 |
-
try:
|
| 305 |
-
link = (entry.get("link", "") or "").strip()
|
| 306 |
-
title = clean_title(entry.get("title", ""))
|
| 307 |
-
|
| 308 |
-
if not link or not title:
|
| 309 |
-
continue
|
| 310 |
-
if link in posted_links or title in posted_titles:
|
| 311 |
-
continue
|
| 312 |
-
|
| 313 |
-
article_text = extract_article_text(entry, link)
|
| 314 |
-
if len(article_text) < 220:
|
| 315 |
-
logging.info("Skipping weak article: %s", title)
|
| 316 |
-
continue
|
| 317 |
-
|
| 318 |
-
image_url = extract_image_from_entry(entry, link)
|
| 319 |
-
|
| 320 |
-
return {
|
| 321 |
-
"mode": "rss",
|
| 322 |
-
"source": source["name"],
|
| 323 |
-
"category": source["category"],
|
| 324 |
-
"hashtags": source["hashtags"],
|
| 325 |
-
"title": title,
|
| 326 |
-
"link": link,
|
| 327 |
-
"text": article_text,
|
| 328 |
-
"image_url": image_url
|
| 329 |
-
}
|
| 330 |
-
except Exception as e:
|
| 331 |
-
logging.warning("Entry skipped due error: %s", e)
|
| 332 |
-
continue
|
| 333 |
-
|
| 334 |
-
return None
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
def init_gemini() -> None:
|
| 338 |
-
genai.configure(api_key=GOOGLE_API_KEY)
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
def discover_gemini_models() -> List[str]:
|
| 342 |
-
"""Return models that support generateContent, ordered by preference."""
|
| 343 |
-
fallback_names = [
|
| 344 |
-
"gemini-2.5-flash",
|
| 345 |
-
"gemini-2.5-flash-lite",
|
| 346 |
-
"gemini-2.0-flash",
|
| 347 |
-
"gemini-2.0-flash-lite",
|
| 348 |
-
"gemini-1.5-flash",
|
| 349 |
-
"gemini-1.5-flash-latest"
|
| 350 |
-
]
|
| 351 |
-
|
| 352 |
-
discovered = []
|
| 353 |
-
try:
|
| 354 |
-
for m in genai.list_models():
|
| 355 |
-
name = getattr(m, "name", "") or ""
|
| 356 |
-
methods = list(getattr(m, "supported_generation_methods", []) or [])
|
| 357 |
-
if "generateContent" in methods:
|
| 358 |
-
# API returns names like "models/gemini-2.0-flash"
|
| 359 |
-
discovered.append(name.replace("models/", ""))
|
| 360 |
-
except Exception as e:
|
| 361 |
-
logging.warning("list_models failed, using fallback model names: %s", e)
|
| 362 |
-
|
| 363 |
-
candidates = []
|
| 364 |
-
if PREFERRED_GEMINI_MODEL:
|
| 365 |
-
candidates.append(PREFERRED_GEMINI_MODEL.replace("models/", ""))
|
| 366 |
-
|
| 367 |
-
for n in fallback_names:
|
| 368 |
-
if n not in candidates:
|
| 369 |
-
candidates.append(n)
|
| 370 |
-
|
| 371 |
-
for n in discovered:
|
| 372 |
-
# Put flash models first, avoid embedding/vision-only/preview if possible.
|
| 373 |
-
low = n.lower()
|
| 374 |
-
if "embedding" in low or "aqa" in low:
|
| 375 |
-
continue
|
| 376 |
-
if n not in candidates:
|
| 377 |
-
candidates.append(n)
|
| 378 |
-
|
| 379 |
-
logging.info("Gemini candidate models: %s", candidates)
|
| 380 |
-
return candidates
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
def generate_with_auto_model(prompt: str, data: Dict[str, Any]) -> Tuple[str, str]:
|
| 384 |
-
init_gemini()
|
| 385 |
-
candidates = discover_gemini_models()
|
| 386 |
-
last_error = None
|
| 387 |
-
|
| 388 |
-
for name in candidates:
|
| 389 |
-
try:
|
| 390 |
-
logging.info("Trying Gemini model: %s", name)
|
| 391 |
-
model = genai.GenerativeModel(name)
|
| 392 |
-
response = model.generate_content(prompt)
|
| 393 |
-
text = (getattr(response, "text", "") or "").strip()
|
| 394 |
-
text = re.sub(r"\n{3,}", "\n\n", text).replace("**", "").strip()
|
| 395 |
-
if len(text) < 80:
|
| 396 |
-
raise RuntimeError(f"Gemini response too short from {name}")
|
| 397 |
-
data["active_gemini_model"] = name
|
| 398 |
-
save_data(data)
|
| 399 |
-
logging.info("Gemini model success: %s", name)
|
| 400 |
-
return text, name
|
| 401 |
-
except Exception as e:
|
| 402 |
-
last_error = e
|
| 403 |
-
logging.warning("Gemini model failed: %s | %s", name, e)
|
| 404 |
-
time.sleep(1)
|
| 405 |
-
|
| 406 |
-
raise RuntimeError(f"All Gemini models failed. Last error: {last_error}")
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
def build_article_prompt(article: Dict[str, Any]) -> str:
|
| 410 |
-
category = article.get("category", "معلومات عامة")
|
| 411 |
-
title = article.get("title", "")
|
| 412 |
-
text = article.get("text", "")
|
| 413 |
-
suggested_hashtags = article.get("hashtags", "#معلومات_عامة")
|
| 414 |
-
|
| 415 |
-
return f"""
|
| 416 |
-
أنت محرر قناة تيليجرام عربية اسمها قلعة المعلومات العامة.
|
| 417 |
-
|
| 418 |
-
حوّل المادة التالية إلى منشور عربي قصير بأسلوب قصة تشويق يشد القارئ حتى النهاية.
|
| 419 |
-
|
| 420 |
-
القواعد المهمة جداً:
|
| 421 |
-
- اكتب عنواناً جذاباً قصيراً في السطر الأول.
|
| 422 |
-
- بعدها اكتب ملخصاً قصصياً من 4 إلى 8 أسطر فقط.
|
| 423 |
-
- لا تستخدم تعداد نقاط.
|
| 424 |
-
- لا تكتب عبارة: أهم النقاط.
|
| 425 |
-
- لا تذكر اسم المصدر داخل المنشور.
|
| 426 |
-
- لا تترجم حرفياً، أعد الصياغة كأنك كاتب محترف.
|
| 427 |
-
- اجعل كل جملة تكمل التي قبلها وتزيد الفضول.
|
| 428 |
-
- لا تخترع معلومة غير موجودة في المادة.
|
| 429 |
-
- لا تبالغ علمياً ولا تكتب ادعاءات غير مؤكدة.
|
| 430 |
-
- اختم النص بإحساس دهشة أو معلومة قوية.
|
| 431 |
-
- أضف في النهاية سطر هاشتاكات مناسب، 3 إلى 6 هاشتاكات.
|
| 432 |
-
- لا تكتب التوقيع، التوقيع سيضاف تلقائياً.
|
| 433 |
-
- الأسل��ب عربي مفهوم قريب للفصحى، مع لمسة سهلة للقارئ العراقي.
|
| 434 |
-
- طول المنشور كله قبل الهاشتاكات لا يتجاوز 900 حرف.
|
| 435 |
-
|
| 436 |
-
التصنيف: {category}
|
| 437 |
-
العنوان الأصلي: {title}
|
| 438 |
-
هاشتاكات مقترحة: {suggested_hashtags}
|
| 439 |
-
|
| 440 |
-
المادة:
|
| 441 |
-
{text}
|
| 442 |
-
"""
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
def build_fallback_prompt(topic: str) -> str:
|
| 446 |
-
return f"""
|
| 447 |
-
اكتب منشور تيليجرام عربي لقناة معلومات عامة عن الموضوع التالي:
|
| 448 |
-
{topic}
|
| 449 |
-
|
| 450 |
-
القواعد:
|
| 451 |
-
- عنوان جذاب قصير في السطر الأول.
|
| 452 |
-
- نص قصصي مشوق من 4 إلى 8 أسطر.
|
| 453 |
-
- كل جملة تقود لما بعدها وتزيد فضول القارئ.
|
| 454 |
-
- لا تستخدم تعداد نقاط.
|
| 455 |
-
- لا تكتب "أهم النقاط".
|
| 456 |
-
- لا تذكر مصادر.
|
| 457 |
-
- لا تخترع أرقاماً دقيقة إذا لم تكن متأكداً.
|
| 458 |
-
- أضف 3 إلى 6 هاشتاكات.
|
| 459 |
-
- لا تضف التوقيع.
|
| 460 |
-
- طول المنشور قبل الهاشتاكات لا يتجاوز 900 حرف.
|
| 461 |
-
"""
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
def generate_post_for_article(article: Dict[str, Any], data: Dict[str, Any]) -> str:
|
| 465 |
-
return generate_with_auto_model(build_article_prompt(article), data)[0]
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
def generate_fallback_article(data: Dict[str, Any]) -> Dict[str, Any]:
|
| 469 |
-
used = set(data.get("posted_titles", []))
|
| 470 |
-
topics = [t for t in FALLBACK_TOPICS if t not in used]
|
| 471 |
-
if not topics:
|
| 472 |
-
topics = FALLBACK_TOPICS[:]
|
| 473 |
-
topic = random.choice(topics)
|
| 474 |
-
|
| 475 |
-
generated, model_name = generate_with_auto_model(build_fallback_prompt(topic), data)
|
| 476 |
-
|
| 477 |
-
return {
|
| 478 |
-
"mode": "fallback",
|
| 479 |
-
"source": f"Gemini:{model_name}",
|
| 480 |
-
"category": "معلومات عامة",
|
| 481 |
-
"title": topic,
|
| 482 |
-
"link": "fallback:" + topic,
|
| 483 |
-
"text": topic,
|
| 484 |
-
"image_url": None,
|
| 485 |
-
"generated_post": generated
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
def build_caption(post: str) -> str:
|
| 490 |
-
caption = post.strip()
|
| 491 |
-
caption = f"{caption}\n\n{SIGNATURE}"
|
| 492 |
-
if len(caption) > 1024:
|
| 493 |
-
caption = caption[:940].rstrip() + f"\n\n{SIGNATURE}"
|
| 494 |
-
return caption
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
def download_image(image_url: str) -> Optional[Path]:
|
| 498 |
-
if not image_url:
|
| 499 |
-
return None
|
| 500 |
-
try:
|
| 501 |
-
r = requests.get(image_url, headers={"User-Agent": USER_AGENT}, timeout=25)
|
| 502 |
-
ct = r.headers.get("content-type", "")
|
| 503 |
-
if r.status_code != 200 or not r.content or "image" not in ct:
|
| 504 |
-
logging.warning("image rejected status=%s content-type=%s", r.status_code, ct)
|
| 505 |
-
return None
|
| 506 |
-
|
| 507 |
-
ext = ".jpg"
|
| 508 |
-
if "png" in ct:
|
| 509 |
-
ext = ".png"
|
| 510 |
-
elif "webp" in ct:
|
| 511 |
-
ext = ".webp"
|
| 512 |
-
elif "gif" in ct:
|
| 513 |
-
return None
|
| 514 |
-
|
| 515 |
-
img_path = DATA_DIR / f"image_{int(time.time())}{ext}"
|
| 516 |
-
img_path.write_bytes(r.content)
|
| 517 |
-
|
| 518 |
-
if img_path.stat().st_size > 9_000_000:
|
| 519 |
-
img_path.unlink(missing_ok=True)
|
| 520 |
-
return None
|
| 521 |
-
|
| 522 |
-
return img_path
|
| 523 |
-
except Exception as e:
|
| 524 |
-
logging.warning("image download failed: %s", e)
|
| 525 |
-
return None
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
def send_to_telegram(bot: Bot, caption: str, image_url: Optional[str] = None) -> None:
|
| 529 |
-
"""
|
| 530 |
-
Telegram sender using Pyrogram.
|
| 531 |
-
Fixed for Flask request threads by creating an asyncio event loop inside the thread.
|
| 532 |
-
Requires Secrets:
|
| 533 |
-
- API_ID
|
| 534 |
-
- API_HASH
|
| 535 |
-
- BOT_TOKEN
|
| 536 |
-
"""
|
| 537 |
-
img_path = download_image(image_url) if image_url else None
|
| 538 |
-
|
| 539 |
-
if not API_ID or not API_HASH:
|
| 540 |
-
raise RuntimeError("API_ID/API_HASH are missing. Add them to HuggingFace Secrets to use Pyrogram sender.")
|
| 541 |
-
|
| 542 |
-
loop = asyncio.new_event_loop()
|
| 543 |
-
asyncio.set_event_loop(loop)
|
| 544 |
-
|
| 545 |
-
try:
|
| 546 |
-
with Client(
|
| 547 |
-
"castle_info_bot",
|
| 548 |
-
api_id=API_ID,
|
| 549 |
-
api_hash=API_HASH,
|
| 550 |
-
bot_token=BOT_TOKEN,
|
| 551 |
-
in_memory=True
|
| 552 |
-
) as app:
|
| 553 |
-
if img_path and img_path.exists():
|
| 554 |
-
try:
|
| 555 |
-
app.send_photo(
|
| 556 |
-
chat_id=TELEGRAM_CHANNEL_ID,
|
| 557 |
-
photo=str(img_path),
|
| 558 |
-
caption=caption
|
| 559 |
-
)
|
| 560 |
-
logging.info("Posted photo to Telegram via Pyrogram")
|
| 561 |
-
return
|
| 562 |
-
except Exception as e:
|
| 563 |
-
logging.warning("Pyrogram photo failed, fallback to text: %s", e)
|
| 564 |
-
|
| 565 |
-
app.send_message(
|
| 566 |
-
chat_id=TELEGRAM_CHANNEL_ID,
|
| 567 |
-
text=caption,
|
| 568 |
-
disable_web_page_preview=True
|
| 569 |
-
)
|
| 570 |
-
logging.info("Posted text to Telegram via Pyrogram")
|
| 571 |
-
|
| 572 |
-
finally:
|
| 573 |
-
if img_path:
|
| 574 |
-
img_path.unlink(missing_ok=True)
|
| 575 |
-
try:
|
| 576 |
-
loop.close()
|
| 577 |
-
except Exception:
|
| 578 |
-
pass
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
def remember_post(data: Dict[str, Any], article: Dict[str, Any], final_text: str) -> None:
|
| 582 |
-
link = article.get("link", "")
|
| 583 |
-
title = article.get("title", "")
|
| 584 |
-
|
| 585 |
-
if link:
|
| 586 |
-
data.setdefault("posted_links", []).append(link)
|
| 587 |
-
if title:
|
| 588 |
-
data.setdefault("posted_titles", []).append(title)
|
| 589 |
-
|
| 590 |
-
data["posted_links"] = data.get("posted_links", [])[-700:]
|
| 591 |
-
data["posted_titles"] = data.get("posted_titles", [])[-700:]
|
| 592 |
-
|
| 593 |
-
data.setdefault("last_posts", []).append({
|
| 594 |
-
"time": datetime.now(pytz.timezone(TIMEZONE)).isoformat(),
|
| 595 |
-
"mode": article.get("mode"),
|
| 596 |
-
"source": article.get("source"),
|
| 597 |
-
"category": article.get("category"),
|
| 598 |
-
"title": title,
|
| 599 |
-
"link": link,
|
| 600 |
-
"image": bool(article.get("image_url")),
|
| 601 |
-
"text_preview": final_text[:250]
|
| 602 |
-
})
|
| 603 |
-
data["last_posts"] = data["last_posts"][-40:]
|
| 604 |
-
data["last_error"] = ""
|
| 605 |
-
save_data(data)
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
def run_once() -> None:
|
| 609 |
-
logging.info("Run started")
|
| 610 |
-
data = load_data()
|
| 611 |
-
bot = Bot(token=BOT_TOKEN)
|
| 612 |
-
|
| 613 |
-
try:
|
| 614 |
-
article = get_candidate_article(data)
|
| 615 |
-
|
| 616 |
-
if article:
|
| 617 |
-
generated = generate_post_for_article(article, data)
|
| 618 |
-
else:
|
| 619 |
-
logging.info("No RSS article found, using fallback B content")
|
| 620 |
-
article = generate_fallback_article(data)
|
| 621 |
-
generated = article["generated_post"]
|
| 622 |
-
|
| 623 |
-
caption = build_caption(generated)
|
| 624 |
-
send_to_telegram(bot, caption, article.get("image_url"))
|
| 625 |
-
remember_post(data, article, caption)
|
| 626 |
-
logging.info("Run completed")
|
| 627 |
-
|
| 628 |
-
except Exception as e:
|
| 629 |
-
logging.exception("Run failed")
|
| 630 |
-
data["last_error"] = f"{datetime.now().isoformat()} | {str(e)}"
|
| 631 |
-
save_data(data)
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
def create_status_html() -> str:
|
| 635 |
-
data = load_data()
|
| 636 |
-
last_posts = data.get("last_posts", [])[-10:]
|
| 637 |
-
rows = ""
|
| 638 |
-
for p in reversed(last_posts):
|
| 639 |
-
rows += f"""
|
| 640 |
-
<tr>
|
| 641 |
-
<td>{p.get('time','')}</td>
|
| 642 |
-
<td>{p.get('category','')}</td>
|
| 643 |
-
<td>{p.get('source','')}</td>
|
| 644 |
-
<td>{p.get('title','')}</td>
|
| 645 |
-
<td>{'نعم' if p.get('image') else 'لا'}</td>
|
| 646 |
-
</tr>
|
| 647 |
-
"""
|
| 648 |
-
|
| 649 |
-
last_error = data.get("last_error") or "لا يوجد"
|
| 650 |
-
total = len(data.get("posted_links", []))
|
| 651 |
-
active_model = data.get("active_gemini_model") or "لم يتم اختياره بعد"
|
| 652 |
-
|
| 653 |
-
return f"""
|
| 654 |
-
<html dir="rtl" lang="ar">
|
| 655 |
-
<head>
|
| 656 |
-
<meta charset="utf-8">
|
| 657 |
-
<title>Castle Info Bot</title>
|
| 658 |
-
<style>
|
| 659 |
-
body {{ font-family: Arial, sans-serif; padding: 30px; background: #f7f7f7; }}
|
| 660 |
-
.card {{ background: white; padding: 20px; border-radius: 14px; box-shadow: 0 2px 12px #ddd; margin-bottom: 20px; }}
|
| 661 |
-
table {{ width:100%; border-collapse: collapse; background: white; }}
|
| 662 |
-
td, th {{ border:1px solid #ddd; padding:10px; }}
|
| 663 |
-
th {{ background:#eee; }}
|
| 664 |
-
code {{ direction:ltr; display:inline-block; white-space: pre-wrap; }}
|
| 665 |
-
</style>
|
| 666 |
-
</head>
|
| 667 |
-
<body>
|
| 668 |
-
<div class="card">
|
| 669 |
-
<h2>قلعة المعلومات العامة - Bot Status</h2>
|
| 670 |
-
<p>الحالة: يعمل ✅</p>
|
| 671 |
-
<p>الجدول: كل ساعتين من 10 صباحاً إلى 10 ليلاً بتوقيت العراق</p>
|
| 672 |
-
<p>موديل Gemini الحالي: <b>{active_model}</b></p>
|
| 673 |
-
<p>عدد الروابط المحفوظة لمنع التكرار: <b>{total}</b></p>
|
| 674 |
-
<p>آخر خطأ: <code>{last_error}</code></p>
|
| 675 |
-
</div>
|
| 676 |
-
<div class="card">
|
| 677 |
-
<h3>آخر المنشورات</h3>
|
| 678 |
-
<table>
|
| 679 |
-
<tr><th>الوقت</th><th>القسم</th><th>المصدر</th><th>العنوان</th><th>صورة</th></tr>
|
| 680 |
-
{rows}
|
| 681 |
-
</table>
|
| 682 |
-
</div>
|
| 683 |
-
<div class="card">
|
| 684 |
-
<p>للتجربة اليدوية افتح: <code>/run-now-secret</code></p>
|
| 685 |
-
</div>
|
| 686 |
-
</body>
|
| 687 |
-
</html>
|
| 688 |
-
"""
|
| 689 |
-
|
| 690 |
-
|
| 691 |
-
app = Flask(__name__)
|
| 692 |
-
|
| 693 |
-
@app.route("/")
|
| 694 |
-
def home():
|
| 695 |
-
return create_status_html()
|
| 696 |
-
|
| 697 |
-
@app.route("/run-now-secret")
|
| 698 |
-
def run_now_secret():
|
| 699 |
-
run_once()
|
| 700 |
-
return "تم تشغيل النشر اليدوي. افحص القناة والسجلات."
|
| 701 |
-
|
| 702 |
-
@app.route("/health")
|
| 703 |
-
def health():
|
| 704 |
-
return "ok"
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
def start_scheduler():
|
| 708 |
-
scheduler = BackgroundScheduler(timezone=TIMEZONE)
|
| 709 |
-
scheduler.add_job(
|
| 710 |
-
run_once,
|
| 711 |
-
"cron",
|
| 712 |
-
hour="10,12,14,16,18,20,22",
|
| 713 |
-
minute=0,
|
| 714 |
-
second=0,
|
| 715 |
-
id="castle_info_posts",
|
| 716 |
-
replace_existing=True,
|
| 717 |
-
max_instances=1,
|
| 718 |
-
coalesce=True,
|
| 719 |
-
misfire_grace_time=300
|
| 720 |
-
)
|
| 721 |
-
scheduler.start()
|
| 722 |
-
logging.info("Scheduler started: %s", POST_HOURS)
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
validate_env()
|
| 726 |
-
init_gemini()
|
| 727 |
-
start_scheduler()
|
| 728 |
-
|
| 729 |
-
if RUN_ON_START:
|
| 730 |
-
try:
|
| 731 |
-
run_once()
|
| 732 |
-
except Exception:
|
| 733 |
-
logging.exception("RUN_ON_START failed")
|
| 734 |
-
|
| 735 |
-
if __name__ == "__main__":
|
| 736 |
-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