import requests import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[3] sys.path.insert(0, str(PROJECT_ROOT)) from core.config import settings BASE_URL = "https://factchecktools.googleapis.com/v1alpha1/claims:search" def verify_claim_google(claim: str): """ Search Google Fact Check Tools API for existing fact-check articles. Returns: { "found": bool, "claim": str, "fact_checks": [ { "publisher": str, "rating": str, "review_url": str, "title": str } ] } """ params = { "query": claim, "key": settings.GOOGLE_FACTCHECK_API_KEY } try: response = requests.get(BASE_URL, params=params) response.raise_for_status() data = response.json() if not data.get("claims"): return { "found": False, "claim": claim, "fact_checks": [] } fact_checks = [] for claim_data in data["claims"]: for review in claim_data.get("claimReview", []): fact_checks.append({ "publisher": review.get("publisher", {}).get("name", ""), "rating": review.get("textualRating", ""), "review_url": review.get("url", ""), "title": claim_data.get("text", "") }) return { "found": len(fact_checks) > 0, "claim": claim, "fact_checks": fact_checks } except Exception as e: print(f"Google Fact Check Error: {e}") return { "found": False, "claim": claim, "fact_checks": [] } if __name__ == "__main__": result = verify_claim_google("India became independent in 1947.") from pprint import pprint pprint(result)