"""Apollo API helper.""" import json from typing import Dict from urllib.request import Request, urlopen from handle_user_changes import config from handle_user_changes.utils import retry @retry() def get_job_categories() -> Dict[int, str]: """Get category ID to name mapping. Returns: Dict[int, str]: Category ID to name mapping. """ req = Request(f'https://{config.APOLLO_API_HOST}/api/job-categories/') req.add_header('Authorization', config.APOLLO_API_KEY) req.add_header('X-User-Id', 'Lambda') content = urlopen(req).read() data = json.loads(content.decode('utf-8')) return {c['id']: c['name'] for c in data}