import requests
import logging
import json


def get_rules(headers):
    """Fetching existing rules
    Args:
        headers: Header to pass

    Returns:
        List of existing rules
    """
    response = requests.get(
        "https://api.twitter.com/2/tweets/search/stream/rules", headers=headers
    )
    logging.info("Fetching existing rules...")
    if response.status_code != 200:
        raise Exception(
            "Cannot get rules (HTTP {}): {}".format(response.status_code, response.text)
        )
    logging.info(json.dumps(response.json()))
    return response.json()