from dotenv import load_dotenv from src.config import get_settings import requests import json import time # Load environment variables from .env file load_dotenv() def test_remotive_api_directly(): """Test Remotive API directly to debug timeout issues.""" settings = get_settings() print(f"šŸ” Testing Remotive API directly...") print(f"🌐 API URL: {settings.remotive_api_url}") # Test different search parameters and timeouts test_cases = [ {"search": "software engineer", "location": "london", "timeout": 30}, {"search": "python", "location": "remote", "timeout": 30}, {"search": "software", "location": "", "timeout": 30}, # No location filter {"search": "", "location": "", "timeout": 30}, # No filters - get all jobs ] for i, test_case in enumerate(test_cases, 1): print( f"\nšŸ“‹ Test {i}: search='{test_case['search']}', location='{test_case['location']}', timeout={test_case['timeout']}s" ) try: params = {} if test_case["search"]: params["search"] = test_case["search"] if test_case["location"]: params["location"] = test_case["location"] print(f" šŸ“‹ Parameters: {params}") start_time = time.time() response = requests.get( settings.remotive_api_url, params=params, timeout=test_case["timeout"] ) end_time = time.time() response_time = end_time - start_time print(f" ā±ļø Response time: {response_time:.2f}s") if response.status_code == 200: data = response.json() jobs = data.get("jobs", []) print(f" āœ… Status: {response.status_code} | Found: {len(jobs)} jobs") if jobs: sample_job = jobs[0] print( f" šŸ“‹ Sample: '{sample_job.get('title', 'N/A')}' at '{sample_job.get('company_name', 'N/A')}' in '{sample_job.get('candidate_required_location', 'N/A')}'" ) break # Found some results, stop testing else: print(f" āš ļø Response OK but no jobs in results") print(f" šŸ“„ Response keys: {list(data.keys())}") else: print( f" āŒ Status: {response.status_code} | Error: {response.text[:100]}" ) except requests.exceptions.Timeout: print(f" ā±ļø TIMEOUT after {test_case['timeout']}s") except Exception as e: print(f" šŸ’„ Exception: {str(e)}") def test_remotive_simple(): """Simple test without any parameters.""" settings = get_settings() print(f"\nšŸ” Testing Remotive API with no parameters (should be fastest)...") try: start_time = time.time() response = requests.get(settings.remotive_api_url, timeout=30) end_time = time.time() response_time = end_time - start_time print(f"ā±ļø Response time: {response_time:.2f}s") if response.status_code == 200: data = response.json() jobs = data.get("jobs", []) print(f"āœ… Success! Found {len(jobs)} total jobs available") if jobs: print( f"šŸ“‹ First job: '{jobs[0].get('title', 'N/A')}' at '{jobs[0].get('company_name', 'N/A')}'" ) else: print(f"āŒ Status: {response.status_code}") print(f"šŸ“„ Response: {response.text[:200]}") except Exception as e: print(f"šŸ’„ Exception: {str(e)}") if __name__ == "__main__": test_remotive_simple() test_remotive_api_directly()