File size: 2,891 Bytes
9e0d988 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
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()
|