π 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.services.job_search_service import JobSearchService | |
from src.services.profile_service import ProfileService | |
from src.config import get_settings | |
import json | |
import os | |
# Load environment variables from .env file | |
load_dotenv() | |
# Debug: Check if Adzuna credentials are loaded | |
settings = get_settings() | |
print( | |
f"π Debug - Adzuna App ID: {'β Set' if settings.adzuna_app_id else 'β Not set'}" | |
) | |
print( | |
f"π Debug - Adzuna App Key: {'β Set' if settings.adzuna_app_key else 'β Not set'}" | |
) | |
print(f"π Debug - Adzuna Country: {settings.adzuna_country}") | |
# Environment variables check | |
print( | |
f"π Debug - ADZUNA_APP_ID env: {'β Set' if os.getenv('ADZUNA_APP_ID') else 'β Not set'}" | |
) | |
print( | |
f"π Debug - ADZUNA_APP_KEY env: {'β Set' if os.getenv('ADZUNA_APP_KEY') else 'β Not set'}" | |
) | |
# Initialize services | |
jb = JobSearchService() | |
profile_service = ProfileService() | |
# Create a sample user profile first (required for job search) | |
user_id = "test_user_001" | |
profile_data = { | |
"skills": ["Python", "JavaScript", "React", "Node.js", "AWS"], | |
"career_goals": "Software Engineer seeking remote opportunities in full-stack development", | |
"location": "Remote", | |
"resume": "Experienced software developer with 5+ years in web development, API design, and cloud platforms", | |
"salary_wish": "$80,000 - $120,000", | |
} | |
# Create user profile | |
print("Creating user profile...") | |
profile_result = profile_service.upsert_profile(user_id, json.dumps(profile_data)) | |
print(f"Profile created: {profile_result}") | |
# Search parameters | |
search_query = "software engineer" | |
location = "london" | |
job_type = "full-time" | |
print(f"\nπ Searching for '{search_query}' jobs in '{location}' ({job_type})...") | |
print("=" * 60) | |
# Run job search (this will fetch from both Remotive and Adzuna) | |
search_results = jb.search_jobs( | |
user_id=user_id, query=search_query, location=location, job_type=job_type | |
) | |
# Display results | |
if search_results.get("success"): | |
jobs = search_results.get("jobs", []) | |
total_found = search_results.get("total_found", 0) | |
print(f"β Found {total_found} jobs") | |
print(f"π Search parameters: {search_results.get('search_params', {})}") | |
# Group jobs by source | |
remotive_jobs = [job for job in jobs if job.get("source") == "remotive"] | |
adzuna_jobs = [job for job in jobs if job.get("source") == "adzuna"] | |
sample_jobs = [job for job in jobs if job.get("source") == "sample"] | |
print(f"\nπ Results breakdown:") | |
print(f" β’ Remotive jobs: {len(remotive_jobs)}") | |
print(f" β’ Adzuna jobs: {len(adzuna_jobs)}") | |
print(f" β’ Sample jobs: {len(sample_jobs)}") | |
# Display top jobs from each source | |
print(f"\nπ TOP REMOTIVE JOBS:") | |
print("-" * 40) | |
for i, job in enumerate(remotive_jobs[:3], 1): | |
print(f"{i}. {job['title']} at {job['company']}") | |
print(f" π {job['location']}") | |
print(f" π― Fit Score: {job['fit_score']}%") | |
print(f" π {job['url']}") | |
print() | |
print(f"\nπ TOP ADZUNA JOBS:") | |
print("-" * 40) | |
for i, job in enumerate(adzuna_jobs[:3], 1): | |
print(f"{i}. {job['title']} at {job['company']}") | |
print(f" π {job['location']}") | |
print(f" π― Fit Score: {job['fit_score']}%") | |
print(f" π {job['url']}") | |
print() | |
# Save detailed results to file | |
with open("job_search_results.json", "w", encoding="utf-8") as f: | |
json.dump(search_results, f, indent=2, default=str) | |
print(f"πΎ Detailed results saved to 'job_search_results.json'") | |
else: | |
print(f"β Search failed: {search_results.get('message', 'Unknown error')}") | |