import requests from typing import Union, List, Dict, Any from urllib.parse import urlencode class Api: """ SMM Panel API Client """ def __init__(self, api_key: str, api_url: str = 'https://smmmain.com/api/v2'): """ Initialize API client Args: api_key (str): Your API key api_url (str, optional): API URL. Defaults to 'https://smmmain.com/api/v2'. """ self.api_key = api_key self.api_url = api_url self.session = requests.Session() self.session.headers.update({ 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' }) def _connect(self, params: Dict[str, Any]) -> Dict[str, Any]: """ Make API request Args: params (Dict[str, Any]): Request parameters Returns: Dict[str, Any]: Response data Raises: Exception: If API request fails """ try: params['key'] = self.api_key response = self.session.post( self.api_url, data=params, headers={'Content-Type': 'application/x-www-form-urlencoded'} ) response.raise_for_status() return response.json() except Exception as e: raise Exception(f"API request failed: {str(e)}") def order(self, data: Dict[str, Any]) -> Dict[str, Any]: """ Add order Args: data (Dict[str, Any]): Order data Returns: Dict[str, Any]: Order response """ return self._connect({ 'action': 'add', **data }) def status(self, order_id: int) -> Dict[str, Any]: """ Get order status Args: order_id (int): Order ID Returns: Dict[str, Any]: Order status """ return self._connect({ 'action': 'status', 'order': order_id }) def multi_status(self, order_ids: List[int]) -> Dict[str, Any]: """ Get multiple orders status Args: order_ids (List[int]): List of order IDs Returns: Dict[str, Any]: Orders status """ return self._connect({ 'action': 'status', 'orders': ','.join(map(str, order_ids)) }) def services(self) -> List[Dict[str, Any]]: """ Get services list Returns: List[Dict[str, Any]]: Services list """ return self._connect({ 'action': 'services' }) def refill(self, order_id: int) -> Dict[str, Any]: """ Refill order Args: order_id (int): Order ID Returns: Dict[str, Any]: Refill response """ return self._connect({ 'action': 'refill', 'order': order_id }) def multi_refill(self, order_ids: List[int]) -> List[Dict[str, Any]]: """ Refill multiple orders Args: order_ids (List[int]): List of order IDs Returns: List[Dict[str, Any]]: Refill responses """ return self._connect({ 'action': 'refill', 'orders': ','.join(map(str, order_ids)) }) def refill_status(self, refill_id: int) -> Dict[str, Any]: """ Get refill status Args: refill_id (int): Refill ID Returns: Dict[str, Any]: Refill status """ return self._connect({ 'action': 'refill_status', 'refill': refill_id }) def multi_refill_status(self, refill_ids: List[int]) -> List[Dict[str, Any]]: """ Get multiple refills status Args: refill_ids (List[int]): List of refill IDs Returns: List[Dict[str, Any]]: Refills status """ return self._connect({ 'action': 'refill_status', 'refills': ','.join(map(str, refill_ids)) }) def cancel(self, order_ids: List[int]) -> List[Dict[str, Any]]: """ Cancel orders Args: order_ids (List[int]): List of order IDs Returns: List[Dict[str, Any]]: Cancel responses """ return self._connect({ 'action': 'cancel', 'orders': ','.join(map(str, order_ids)) }) def balance(self) -> Dict[str, Any]: """ Get balance Returns: Dict[str, Any]: Balance information """ return self._connect({ 'action': 'balance' }) # Example usage: """ api = Api('YOUR_API_KEY') # Get services services = api.services() print(services) # Get balance balance = api.balance() print(balance) # Add order order = api.order({ 'service': 1, 'link': 'http://example.com/test', 'quantity': 100, 'runs': 2, 'interval': 5 }) print(order) # Get order status status = api.status(123) print(status) # Get multiple orders status statuses = api.multi_status([1, 2, 3]) print(statuses) # Refill order refill = api.refill(123) print(refill) # Refill multiple orders refills = api.multi_refill([1, 2, 3]) refill_ids = [r['refill'] for r in refills if 'refill' in r] if refill_ids: refill_statuses = api.multi_refill_status(refill_ids) print(refill_statuses) # Cancel orders cancels = api.cancel([1, 2, 3]) print(cancels) """