Skip to content
This repository was archived by the owner on Jan 18, 2026. It is now read-only.
This repository was archived by the owner on Jan 18, 2026. It is now read-only.

safer regex solution #1

Description

@github-actions

homeId = int(re.search(r"^/team/([0-9]+)-[\w-]+$", match["HomeTeam"]["Link"]).group(1)) # type: ignore # pylint: disable=line-too-long

awayId = int(re.search(r"^/team/([0-9]+)-[\w-]+$", match["AwayTeam"]["Link"]).group(1)) # type: ignore # pylint: disable=line-too-long

https://github.com/dxstiny/cevlib/blob/6fa393b99e515247dd57b397a8a2a9f65e383958/cevlib/competitions.py#L258

    @property
    def pools(self) -> List[Pool]:
        return self._pools

    def get(self, index: int) -> Optional[Pool]:
        """pools[index]"""
        return self.pools[index] if index < len(self.pools) else None

    @staticmethod
    def ParsePool(pool: Dict[str, Any],
                  competition: CompetitionLink,
                  standings: Optional[StandingsPool]) -> Pool:
        pdex = DictEx(pool)
        draws: List[List[CalendarMatch]] = [ ]
        for match in pdex.ensureList("Results"):
            mdex = DictEx(match)
            homeId = 0
            awayId = 0
            try: # TODO safer regex solution
                homeId = int(re.search(r"^\/team\/([0-9]+)-[\w-]+$", match["HomeTeam"]["Link"]).group(1)) # type: ignore # pylint: disable=line-too-long
                awayId = int(re.search(r"^\/team\/([0-9]+)-[\w-]+$", match["AwayTeam"]["Link"]).group(1)) # type: ignore # pylint: disable=line-too-long
            except Exception as exc:
                print(exc)

            newMatch = CalendarMatch(mdex.ensureString("MatchCentreUrl"),
                CompetitionModel.BuildPlain(competition.name,
                    competition.gender,
                    season = str(competition.age) if competition.age else None,
                    phase = pdex.ensureString("Name"),
                    matchNumber = mdex.ensureString("MatchName")),
                Team.Build(mdex.ensureDictChain("HomeTeam").ensureString("Name"),
                    mdex.ensureDictChain("HomeTeam").ensureDictChain("Logo").ensureString("Name"),
                    "N/A",
                    True,
                    homeId),
                Team.Build(mdex.ensureDictChain("AwayTeam").ensureString("Name"),
                    mdex.ensureDictChain("AwayTeam").ensureDictChain("Logo").ensureString("Name"),
                    "N/A",
                    False,
                    awayId),
                mdex.ensureString("Location"),
                mdex.ensureString("MatchDateTime"),
                Result.ParseFromForm(match),
                mdex.ensureBool("IsComplete"))
            newDraw = True
            for draw in draws:
                if draw[0].awayTeam.name == newMatch.homeTeam.name and \
                   draw[0].homeTeam.name == newMatch.awayTeam.name:
                    newDraw = False
                    draw.append(newMatch)
                    break
            if newDraw:
                draws.append([newMatch])
        return Pool(pdex.ensureString("Name"),
                    [ Draw([ match for match in draw ])
                      for draw in draws ],
                    standings)

    def __repr__(self) -> str:
        return f"(cevlib.competitions.Round) {self._name} ({len(self.pools)} pools)"

    def toJson(self) -> Dict[str, Any]:
        return {
            "name": self._name,
            "pools": [ pool.toJson() for pool in self._pools ]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions