π Add debug logging to JobSearchService for Remotive API responses, including URL, parameters, job count, and error handling.
9e0d988
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() | |