from dotenv import load_dotenv from src.config import get_settings import requests import json # Load environment variables from .env file load_dotenv() def test_adzuna_api_variations(): """Test Adzuna API with different search variations.""" settings = get_settings() print(f"šŸ” Testing Adzuna API with multiple variations...") print(f"šŸ” App ID: {'āœ… Set' if settings.adzuna_app_id else 'āŒ Not set'}") print(f"šŸ” App Key: {'āœ… Set' if settings.adzuna_app_key else 'āŒ Not set'}") if not settings.adzuna_app_id or not settings.adzuna_app_key: print("āŒ Missing Adzuna credentials!") return # Test different combinations test_cases = [ {"country": "gb", "what": "software engineer", "where": "london"}, {"country": "gb", "what": "python developer", "where": "london"}, {"country": "gb", "what": "software", "where": ""}, {"country": "us", "what": "software engineer", "where": "remote"}, {"country": "us", "what": "python", "where": "new york"}, {"country": "gb", "what": "", "where": "london"}, # Just location search ] for i, test_case in enumerate(test_cases, 1): print( f"\nšŸ“‹ Test {i}: Country={test_case['country']}, What='{test_case['what']}', Where='{test_case['where']}'" ) try: base_url = ( f"https://api.adzuna.com/v1/api/jobs/{test_case['country']}/search/1" ) params = { "app_id": settings.adzuna_app_id, "app_key": settings.adzuna_app_key, "what": test_case["what"], "where": test_case["where"], "results_per_page": 5, "content-type": "application/json", } response = requests.get(base_url, params=params, timeout=10) if response.status_code == 200: data = response.json() results = data.get("results", []) count = data.get("count", 0) print( f" āœ… Status: {response.status_code} | Found: {len(results)} jobs | Total available: {count}" ) if results: sample_job = results[0] print( f" šŸ“‹ Sample: '{sample_job.get('title', 'N/A')}' at '{sample_job.get('company', {}).get('display_name', 'N/A')}' in '{sample_job.get('location', {}).get('display_name', 'N/A')}'" ) break # Found some results, stop testing else: print( f" āŒ Status: {response.status_code} | Error: {response.text[:100]}" ) except Exception as e: print(f" šŸ’„ Exception: {str(e)}") if __name__ == "__main__": test_adzuna_api_variations()