Spaces:
Sleeping
Sleeping
| import os | |
| import requests | |
| from dotenv import load_dotenv | |
| load_dotenv(".env") | |
| API_KEY = os.getenv("GOOGLE_API_KEY") | |
| CSE_ID = os.getenv("GOOGLE_CSE_ID") | |
| # QUERY = "OpenAI GPT-4" | |
| QUERY = "IPL 2025 final points table predictions team performance analysis" | |
| if not API_KEY or not CSE_ID: | |
| print("Missing API key or Search Engine ID") | |
| exit(1) | |
| params = { | |
| "q": QUERY, | |
| "key": API_KEY, | |
| "cx": CSE_ID | |
| } | |
| response = requests.get("https://www.googleapis.com/customsearch/v1", params=params) | |
| if response.status_code != 200: | |
| print("Error:", response.status_code, response.text) | |
| else: | |
| data = response.json() | |
| results = data.get("items", []) | |
| if not results: | |
| print("API is working, but no search results found.") | |
| else: | |
| for i, result in enumerate(results[:3], 1): | |
| print(f"\nResult {i}:") | |
| print("Title:", result.get("title")) | |
| print("Link:", result.get("link")) | |
| print("Snippet:", result.get("snippet")) | |