| import logging | |
| from duckduckgo_search import DDGS | |
| logger = logging.getLogger("ONYX") | |
| class WebIntelligenceEngine: | |
| def __init__(self): | |
| self.max_results = 5 | |
| # ========================= | |
| # WEB SEARCH | |
| # ========================= | |
| def search(self, query): | |
| try: | |
| results = [] | |
| with DDGS() as ddgs: | |
| search_results = ddgs.text( | |
| query, | |
| max_results=self.max_results | |
| ) | |
| for r in search_results: | |
| results.append({ | |
| "title": r.get("title"), | |
| "link": r.get("href"), | |
| "snippet": r.get("body") | |
| }) | |
| logger.info(f"Web search results: {len(results)}") | |
| return results | |
| except Exception as e: | |
| logger.error(f"Web search error: {e}") | |
| return [] | |
| # ========================= | |
| # ANALYZE RESULTS | |
| # ========================= | |
| def analyze_trend(self, query): | |
| results = self.search(query) | |
| if not results: | |
| return "Aucune information trouvée." | |
| analysis = f"Tendances trouvées pour : {query}\n\n" | |
| for r in results: | |
| title = r.get("title", "") | |
| snippet = r.get("snippet", "") | |
| analysis += f"- {title}\n" | |
| analysis += f" {snippet}\n\n" | |
| return analysis |