Пример #1
0
    def get_by_id(id: int):
        assert (
            id
            is not None), "Event.get_by_id cannot have None for id parameter"
        data = NI.query(queries.get_event_by_id, {'id': id})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException(id)

            return Event.parse(event_data)
        except AttributeError as e:
            raise NoEventDataException(id)
Пример #2
0
    def get_phase_groups(self):
        assert (self.id is not None
                ), "tournament id cannot be None if calling get_phase_groups"

        phase_groups = []
        data = NI.query(queries.get_tournament_phase_groups, {'id': self.id})
        validate_data(data)

        tournament_data = data['data']['tournament']
        if tournament_data is None:
            raise NoTournamentDataException(self.slug)

        event_data = tournament_data['events']
        if event_data is None:
            raise NoEventDataException(self.slug)

        phase_groups_data = [event['phaseGroups'] for event in event_data]
        for phase_group in phase_groups_data:
            if phase_group is None:
                raise NoPhaseGroupDataException(self.slug)
            [
                phase_groups.append(PhaseGroup.parse(phase_group_data))
                for phase_group_data in phase_group
            ]

        return phase_groups
Пример #3
0
    def get_phase_groups(self):
        assert (
            self.id
            is not None), 'event id cannot be None if calling get_phase_groups'
        Logger.info('Getting Phase Groups for Event: {0}:{1}'.format(
            self.id, self.name))
        data = NI.query(queries.get_event_phase_groups, {'id': self.id})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException(self.identifier)

            phase_groups_data = event_data['phaseGroups']
            if phase_groups_data is None:
                raise NoPhaseGroupDataException(self.identifier)

            return [
                PhaseGroup.parse(phase_group_data)
                for phase_group_data in phase_groups_data
            ]
        except AttributeError as e:
            raise Exception(
                "No phase group data pulled back for event {}".format(
                    self.identifier))
Пример #4
0
    def get(tournament_slug: str, event_slug: str):
        assert (tournament_slug is not None
                ), 'Event.get cannot have None for tournament_slug parameter'
        assert (
            event_slug
            is not None), 'Event.get cannot have None for event_slug parameter'
        slug = "tournament/{0}/event/{1}".format(tournament_slug, event_slug)
        data = NI.query(queries.get_event_by_slugs, {"slug": slug})
        validate_data(data)

        try:
            event_data = data['data']['event']
            if event_data is None:
                raise NoEventDataException('{}:{}'.format(
                    tournament_slug, event_slug))

            return Event.parse(event_data)
        except AttributeError as e:
            raise NoEventDataException('{}:{}'.format(tournament_slug,
                                                      event_slug))
Пример #5
0
    def get_events(self):
        assert (
            self.id
            is not None), "tournament id cannot be None if calling get_events"
        data = NI.query(queries.get_tournament_events, {'id': self.id})
        validate_data(data)

        tournament_data = data['data']['tournament']
        if tournament_data is None:
            raise NoTournamentDataException(self.slug)

        base_data = tournament_data['events']
        if base_data is None:
            raise NoEventDataException(self.slug)

        return [Event.parse(event_data) for event_data in base_data]
Пример #6
0
 def validate_data(input: dict, id: int = 0):
     if 'data' in input:
         raise DataMalformedException(input)
     if 'event' not in input or input['event'] is None:
         raise NoEventDataException(id)