import json, requests
from api_auth import APICredentials, APIParams
channel_id = '02ed9f65570746528e7b3d0628960025' # Replace with the ID for the desired live channel.

class Blackout:
    def __init__(self):
        self.host = "https://services.uplynk.com"

    def run(self):
        """
        Adds a blackout configuration to a live channel.
        """
        self._create_blackout()

    def _create_blackout(self):
        url = "{}{}{}{}".format(self.host, "/api/v4/channels/", channel_id, "/blackouts")

        payload = {
            'desc': 'Blackout North America', # Replace with the live channel's name.
            'blackout_id': 'BNA', # Replace with the desired blackout ID.
            'rules': ['abce337d51f04b6da043cc7f28c9fe2f'] # Replace with the ID for the desired blackout rule.
        }

        headers = {'Content-Type': 'application/json'}

        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers 
        )

        print(response.json())

Blackout().run()