zhenxun_bot/zhenxun/utils/github_utils/__init__.py
AkashiCoin f11e9c58e4 🔨 提取GitHub相关操作 (#1609)
* 🔨 提取GitHub相关操作

* 🔨 重构API策略
2024-09-08 12:38:30 +08:00

24 lines
720 B
Python

from .consts import GITHUB_REPO_URL_PATTERN
from .func import get_fastest_raw_format, get_fastest_archive_format
from .models import RepoAPI, RepoInfo, GitHubStrategy, JsdelivrStrategy
__all__ = [
"parse_github_url",
"get_fastest_raw_format",
"get_fastest_archive_format",
"api_strategy",
]
def parse_github_url(github_url: str) -> "RepoInfo":
if matched := GITHUB_REPO_URL_PATTERN.match(github_url):
return RepoInfo(**{k: v for k, v in matched.groupdict().items() if v})
raise ValueError("github地址格式错误")
# 使用
jsdelivr_api = RepoAPI(JsdelivrStrategy()) # type: ignore
github_api = RepoAPI(GitHubStrategy()) # type: ignore
api_strategy = [jsdelivr_api, github_api]