CoolFace
Apppublic

akv2011/Linkedin_reach

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
debug_search.py67 linesDownload Raw Back to synapse-agent
1#!/usr/bin/env python32"""3Debug script to test Google Custom Search API4"""5 6import os7import sys8from dotenv import load_dotenv9from googleapiclient.discovery import build10 11# Load environment12load_dotenv('.env')13 14def test_google_search():15    """Test Google Custom Search API"""16    print("๐Ÿ” Testing Google Custom Search API...")17    18    api_key = os.getenv("GOOGLE_API_KEY")19    cse_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID")20    21    print(f"API Key: {'โœ“ Set' if api_key else 'โœ— Missing'}")22    print(f"CSE ID: {'โœ“ Set' if cse_id else 'โœ— Missing'}")23    24    if not api_key or not cse_id:25        print("โŒ Missing API credentials")26        return27    28    try:29        service = build("customsearch", "v1", developerKey=api_key)30        31        # Test 1: Simple LinkedIn search32        print("\n๐Ÿ“ Test 1: Simple LinkedIn search")33        query = "software engineer site:linkedin.com/in/"34        print(f"Query: {query}")35        36        res = service.cse().list(q=query, cx=cse_id, num=3).execute()37        38        if 'items' in res:39            print(f"โœ“ Found {len(res['items'])} results")40            for i, item in enumerate(res['items'][:2]):41                print(f"  {i+1}. {item['title']}")42                print(f"     {item['link']}")43        else:44            print("โŒ No results found")45            print(f"Response: {res}")46            47        # Test 2: General search (no site restriction)48        print("\n๐Ÿ“ Test 2: General search")49        query = "software engineer"50        print(f"Query: {query}")51        52        res = service.cse().list(q=query, cx=cse_id, num=3).execute()53        54        if 'items' in res:55            print(f"โœ“ Found {len(res['items'])} results")56            for i, item in enumerate(res['items'][:2]):57                print(f"  {i+1}. {item['title']}")58        else:59            print("โŒ No results found")60            61    except Exception as e:62        print(f"โŒ Error: {e}")63        print(f"Error type: {type(e)}")64 65if __name__ == "__main__":66    test_google_search()67