Spaces:
Sleeping
Sleeping
File size: 921 Bytes
f98de7e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import os
import requests
from dotenv import load_dotenv
load_dotenv()
# You found this CID in your previous Serper request (e.g., Veera 5)
place_cid = "1433095058555445262"
# Note: This uses SerpApi (serpapi.com), NOT Serper.dev
url = "https://serpapi.com/search"
api_key = os.getenv("SERPAPI_API_KEY")
if not api_key:
raise RuntimeError(
"SERPAPI_API_KEY is missing. Set it in .env (local) or Hugging Face Secrets."
)
params = {
"engine": "google_maps_reviews", # This engine fetches the TEXT
"data_id": f"0x0:0x{hex(int(place_cid))[2:]}", # Convert CID to Data ID format
"api_key": api_key,
}
response = requests.get(url, params=params, timeout=30)
response.raise_for_status()
reviews = response.json().get("reviews", [])
for r in reviews[:3]:
print(f"User said: {r.get('snippet')}")
# AI can now read this: "Great food but rude waiter..."
|