Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test Adzuna API with the provided credentials | |
| """ | |
| import os | |
| import sys | |
| import requests | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Get credentials | |
| app_id = os.getenv("ADZUNA_APP_ID") | |
| app_key = os.getenv("ADZUNA_APP_KEY") | |
| # Validate that required environment variables are set | |
| if not app_id or not app_key: | |
| print("β CRITICAL: ADZUNA_APP_ID and ADZUNA_APP_KEY must be set in environment") | |
| print(" Please set these in your .env file or environment variables") | |
| sys.exit(1) | |
| print("π Testing Adzuna API") | |
| print("=" * 50) | |
| print(f"App ID: {app_id}") | |
| print(f"App Key: {app_key[:10]}...{app_key[-4:]}") | |
| # Test API directly | |
| url = "https://api.adzuna.com/v1/api/jobs/gb/search/1" | |
| params = { | |
| "app_id": app_id, | |
| "app_key": app_key, | |
| "what": "Python Developer", | |
| "where": "London", | |
| "results_per_page": 5 | |
| } | |
| print("\nπ‘ Calling Adzuna API...") | |
| try: | |
| response = requests.get(url, params=params, timeout=10) | |
| if response.status_code == 200: | |
| data = response.json() | |
| total = data.get("count", 0) | |
| results = data.get("results", []) | |
| print(f"\nβ SUCCESS! API responded with {total} total jobs") | |
| print(f" Showing first {len(results)} results:\n") | |
| for i, job in enumerate(results[:3], 1): | |
| print(f"{i}. {job.get('title', 'No title')}") | |
| print(f" Company: {job.get('company', {}).get('display_name', 'N/A')}") | |
| print(f" Location: {job.get('location', {}).get('display_name', 'N/A')}") | |
| # Salary info | |
| if job.get("salary_min"): | |
| print(f" Salary: Β£{job['salary_min']:,.0f} - Β£{job.get('salary_max', 0):,.0f}") | |
| # URL | |
| if job.get("redirect_url"): | |
| print(f" URL: {job['redirect_url'][:50]}...") | |
| print() | |
| print("π Adzuna API is working perfectly with your keys!") | |
| elif response.status_code == 401: | |
| print(f"β Authentication failed: {response.text}") | |
| print("\nPlease check your API keys.") | |
| else: | |
| print(f"β API Error: {response.status_code}") | |
| print(f"Response: {response.text}") | |
| except requests.exceptions.ConnectionError: | |
| print("β Connection error - check your internet connection") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| # Now test with the aggregator | |
| print("\n" + "=" * 50) | |
| print("Testing with Job Aggregator...") | |
| sys.path.insert(0, '.') | |
| try: | |
| from services.job_aggregator import JobAggregator | |
| aggregator = JobAggregator() | |
| jobs = aggregator.search_adzuna("Software Engineer", "United States") | |
| if jobs: | |
| print(f"β Aggregator found {len(jobs)} jobs") | |
| for job in jobs[:2]: | |
| print(f" β’ {job.title} at {job.company}") | |
| else: | |
| print("β οΈ No jobs returned from aggregator") | |
| except Exception as e: | |
| print(f"β Aggregator error: {e}") |