Ejemplo n.º 1
0
    def api_version(self):
        """The version of the API that is currently in use.

        :rtype: int
        """
        data = request("/", headers=self._headers)
        return data["version"]
Ejemplo n.º 2
0
 def __init__(self, event_key: str, headers: dict):
     self._event_key = event_key
     self._headers = headers
     info = request(f"/event/{self._event_key}", headers=self._headers)
     info = info[0]
     season_key = int(info["season_key"])
     self.season = Season(season_key).name
     self.region = info["region_key"]
     self.league = info["league_key"]
     self.name = info["event_name"]
     location = f"{info['city']} {info['state_prov']}, {info['country']}"
     self.location = location
     self.venue = info["venue"]
     logger.info(
         f"Initialized 'Event' object with event key of {self._event_key}")
Ejemplo n.º 3
0
 def __init__(self, team_number: int, headers: dict):
     self._team_number = team_number
     self._headers = headers
     team = request(target=f"/team/{team_number}", headers=headers)
     team = team[0]
     self.region = team["region_key"]
     self.league = team["league_key"]
     self.short_name = team["team_name_short"]
     self.long_name = team["team_name_long"]
     self.robot_name = team["robot_name"]
     location = f"{team['city']}, {team['state_prov']}, {team['country']}, {team['zip_code']}"
     self.location = location
     self.rookie_year = team["rookie_year"]
     self.last_active = team["last_active"]
     self.website = team["website"]
     logger.info(
         f"Initialized 'Team' object with team number of {self._team_number}"
     )
Ejemplo n.º 4
0
    def events(self, season: Season):
        """
        Every event the team has participated in, in a particular season.

        Args:
            season (:class:`~alliancepy.season.Season`): An alliancepy Season object
        Returns:
            dict: A dict containing the :class:`~alliancepy.event.Event` objects. The key names correspont to the name \
            of the event.
        """
        q = queue.Queue()
        headers = self._headers

        def worker():
            while True:
                event_key = q.get()
                e = Event(event_key=event_key, headers=headers)
                raw_key = str(e.name)
                key = raw_key.replace(" ", "_")
                key = key.lower()
                if key in edict:
                    raw_key_right = re.sub(r"\d{4}-\w+-", "", event_key)
                    raw_key_right = raw_key_right.lower()
                    key = f"{key}_{raw_key_right}"
                edict[key] = e
                q.task_done()

        threading.Thread(target=worker, daemon=True).start()
        logger.info("Started worker")

        edict = {}
        events = request(f"/team/{self._team_number}/events/{season}",
                         headers=self._headers)
        logger.info("Sending task requests to worker")
        for event in events:
            q.put(event["event_key"])

        logger.info("Processing units in queue")
        q.join()
        logger.info("Done processing, finishing up")
        return edict
Ejemplo n.º 5
0
    def match(self, match_type: MatchType, match_number: int):
        """
        Get one of the matches for the event.

        Args:
            match_type (:class:`~alliancepy.match_type.MatchType`): The type of the match. See :ref:`match_type` for \
            more information.
            match_number (int): The number of the match.
        Return:
            :class:`alliancepy.match.Match`: A :class:`~alliancepy.match.Match` object containing details about the \
            specific match.
        """
        logger.info(
            f"Got request to create Match object with type {match_type} and number of {match_number}"
        )
        if len(str(match_number)) == 1:
            match_name = f"{match_type.value}00{match_number}"
        elif len(str(match_number)) == 2:
            match_name = f"{match_type.value}0{match_number}"
        else:
            match_name = f"{match_type.value}{match_number}"
        matches = request(f"/event/{self._event_key}/matches",
                          headers=self._headers)
        mdict = {}
        for match in matches:
            key = match["match_key"]
            logger.info(f"Processing match key {key}")
            key_right_strip = re.sub(r"\d{4}-\w+-\w+-", "", key)
            value = re.sub(r"-\d+", "", key_right_strip)
            mdict[key] = value
        try:
            logger.info("Performing reverse lookup of match key")
            match_key = list(mdict.keys())[list(mdict.values()).index(
                match_name.upper())]
        except ValueError:
            logger.error(f"This match does not exist!")
            raise ValueError("This match does not exist")
        else:
            logger.info(
                f"Sucessfully fetched match key, returning Match object")
            return Match(match_key, headers=self._headers)
Ejemplo n.º 6
0
 def _rankings(self, season: Season):
     logger.info("Getting ranking data")
     rankings = request(f"/team/{self._team_number}/results/{season}",
                        headers=self._headers)
     return rankings
Ejemplo n.º 7
0
 def _wlt(self):
     logger.info("Fetching WLT data")
     data = request(target=f"/team/{self._team_number}/wlt",
                    headers=self._headers)
     return data[0]
Ejemplo n.º 8
0
 def clear_cache(self):
     """Clears the cache. This is useful for long-running applications when the cache gets too big."""
     request("clear", headers=self._headers)
Ejemplo n.º 9
0
 def _rankings(self):
     logger.info("Getting rankings data...")
     resp = request(f"/event/{self._event_key}/rankings",
                    headers=self._headers)
     return resp