suggestion_bot / test_api_response.py
Sanjay Ram A
Upload 52 files
75788a5 verified
Raw
History Blame Contribute Delete
1.62 kB
"""Test script to check what Google Shopping Light API returns."""
from serpapi import GoogleSearch
from config import settings
import json
def test_api_response():
"""Check what fields the API returns."""
print("=" * 70)
print("Testing Google Shopping Light API Response")
print("=" * 70)
params = {
"engine": "google_shopping_light",
"q": "mobile under 2000 INR",
"gl": "in",
"hl": "en",
"api_key": settings.serpapi_api_key,
"max_price": 2000
}
print("\n[Params]")
print(json.dumps({k: v for k, v in params.items() if k != "api_key"}, indent=2))
print("\n[Calling API...]")
search = GoogleSearch(params)
results = search.get_dict()
shopping_results = results.get("shopping_results", [])
print(f"\n[Found {len(shopping_results)} products]")
if shopping_results:
print("\n[First Product Fields]:")
first = shopping_results[0]
for key, value in first.items():
# Truncate long values
value_str = str(value)[:100] if len(str(value)) > 100 else str(value)
print(f" {key}: {value_str}")
print("\n[Link Field Check]:")
print(f" 'link' exists: {'link' in first}")
print(f" 'product_link' exists: {'product_link' in first}")
if 'product_link' in first:
print(f" product_link value: {first['product_link']}")
if 'link' in first:
print(f" link value: {first['link']}")
print("\n" + "=" * 70)
if __name__ == "__main__":
test_api_response()