summaryrefslogtreecommitdiff
path: root/ATRI/utils
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2022-03-20 09:06:49 +0800
committerKyomotoi <[email protected]>2022-03-20 09:08:14 +0800
commit9ebeff70994191abe6052e53bb58541f08917f5a (patch)
treee0374902efeb615e0b2f2d78bc36d243d3b727a9 /ATRI/utils
parent019b69003719f90a1c687bdb41e6b395d338d3fa (diff)
downloadATRI-9ebeff70994191abe6052e53bb58541f08917f5a.tar.gz
ATRI-9ebeff70994191abe6052e53bb58541f08917f5a.tar.bz2
ATRI-9ebeff70994191abe6052e53bb58541f08917f5a.zip
✨ 添加更新检查
Diffstat (limited to 'ATRI/utils')
-rw-r--r--ATRI/utils/check_update.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/ATRI/utils/check_update.py b/ATRI/utils/check_update.py
new file mode 100644
index 0000000..b2f8b53
--- /dev/null
+++ b/ATRI/utils/check_update.py
@@ -0,0 +1,58 @@
+from ATRI.exceptions import RequestError
+
+from . import request
+
+
+REPO_COMMITS_URL = "https://api.github.com/repos/Kyomotoi/ATRI/commits"
+REPO_RELEASE_URL = "https://api.github.com/repos/Kyomotoi/ATRI/releases"
+
+
+class CheckUpdate:
+
+ @staticmethod
+ async def _get_commits_info() -> dict:
+ req = await request.get(REPO_COMMITS_URL)
+ return req.json()
+
+ @staticmethod
+ async def _get_release_info() -> dict:
+ req = await request.get(REPO_RELEASE_URL)
+ return req.json()
+
+ @classmethod
+ async def show_latest_commit_info(cls) -> str:
+ try:
+ data = await cls._get_commits_info()
+ except RequestError:
+ raise RequestError("Getting commit info timeout...")
+
+ try:
+ commit_data: dict = data[0]
+ except Exception:
+ raise Exception("GitHub has been error!!!")
+
+ c_info = commit_data["commit"]
+ c_msg = c_info["message"]
+ c_sha = commit_data["sha"][0:5]
+ c_time = c_info["author"]["date"]
+
+ return f"Latest commit {c_msg} | sha: {c_sha} | time: {c_time}"
+
+ @classmethod
+ async def show_latest_version(cls) -> tuple:
+ try:
+ data = await cls._get_release_info()
+ except RequestError:
+ raise RequestError("Getting release list timeout...")
+
+ try:
+ release_data: dict = data[0]
+ except Exception:
+ raise Exception("GitHub has been error!!!")
+
+ l_v = release_data["tag_name"]
+ l_v_t = release_data["published_at"]
+ return l_v, l_v_t
+
+
+