<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_tournaments(self, only_active=True):
 """Get all tournaments Args: only_active (bool):
 Flag to indicate of only active tournaments should be returned or all of them. Defaults to True. Returns: list of dicts: list of tournaments Each tournaments' dict contains the following items: * id (`str`) * name (`str`) * tournament (`int`) * active (`bool`) Example: [ { 'id': '2ecf30f4-4b4f-42e9-8e72-cc5bd61c2733', 'name': 'alpha', 'tournament': 1, 'active': True}, { 'id': '6ff44cca-263d-40bd-b029-a1ab8f42798f', 'name': 'bravo', 'tournament': 2, 'active': True}, { 'id': 'ebf0d62b-0f60-4550-bcec-c737b168c65d', 'name': 'charlie', 'tournament': 3 'active': False}, { 'id': '5fac6ece-2726-4b66-9790-95866b3a77fc', 'name': 'delta', 'tournament': 4, 'active': True}] """

        query = """
            query {
              tournaments {
                id
                name
                tournament
                active
            }
        }
        """
        data = self.raw_query(query)['data']['tournaments']
        if only_active:
            data = [d for d in data if d['active']]
        return data