Download agents/scraper.py from RDS777/SKKAI: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/RDS777/SKKAI/resolve/main/agents/scraper.py
- Command line
-
hf download hf://spaces/RDS777/SKKAI/agents/scraper.py
-
curl -L -o scraper.py https://huggingface.co/spaces/RDS777/SKKAI/resolve/main/agents/scraper.py
1.07 kB
| import re | |
| from typing import List | |
| import feedparser | |
| import requests | |
| FEEDS: List[str] = [ | |
| "https://feeds.bbci.co.uk/news/business/rss.xml", | |
| "https://www.lemonde.fr/economie/rss_full.xml", | |
| ] | |
| HEADERS = {"User-Agent": "Mozilla/5.0 (Sky-LG scraper)"} | |
| FALLBACK_CONTEXT = "Aucune donnée web disponible. Marché supposé stable." | |
| def _clean(text: str) -> str: | |
| return re.sub(r"\s+", " ", re.sub(r"<[^>]+>", "", text or "")).strip() | |
| def fetch_web_context(max_items_per_feed: int = 4, timeout: int = 8) -> str: | |
| titles: List[str] = [] | |
| for url in FEEDS: | |
| try: | |
| r = requests.get(url, headers=HEADERS, timeout=timeout) | |
| r.raise_for_status() | |
| feed = feedparser.parse(r.content) | |
| for entry in feed.entries[:max_items_per_feed]: | |
| title = _clean(entry.get("title", "")) | |
| if title: | |
| titles.append(title) | |
| except Exception as e: | |
| print(f"[scraper] {url}: {e}") | |
| if not titles: | |
| return FALLBACK_CONTEXT | |
| return " | ".join(titles)[:1500] |