"""Admin 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_markets() -> Dict[int, str]: """Get market ID to name mapping. Returns: Dict[int, str]: Market ID to name mapping. """ req = Request(f'https://{config.ADMIN_API_HOST}/markets') req.add_header('filtrauthentication', config.ADMIN_API_KEY) content = urlopen(req).read() data = json.loads(content.decode('utf-8')) return {m['id']: m['name'] for m in data}