Skip to content

Commit

Permalink
✨ feat(cli): add update check for tsticker package
Browse files Browse the repository at this point in the history
Added functionality to check for package updates via PyPI. Updated
`pyproject.toml` version to 0.1.10.
  • Loading branch information
sudoskys committed Oct 5, 2024
1 parent 882d4ed commit cbd9763
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tsticker"
version = "0.1.9"
version = "0.1.10"
description = "Telegram sticker management tool"
authors = [
{ name = "sudoskys", email = "coldlando@hotmail.com" },
Expand All @@ -17,7 +17,7 @@ dependencies = [
"aiohttp>=3.9.5",
"emoji>=2.12.1",
"setuptools>=70.3.0",
"telegram-sticker-utils>=0.2.12",
"telegram-sticker-utils>=0.2.13",
]
requires-python = ">=3.9,<3.13"
readme = "README.md"
Expand Down
28 changes: 28 additions & 0 deletions src/tsticker/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import atexit
import importlib.metadata as metadata
import os
import pathlib
from asyncio import Semaphore
Expand All @@ -8,7 +9,9 @@
from typing import Literal, Optional

import asyncclick as click
import click
import keyring
import requests
from magika import Magika
from pydantic import BaseModel, ValidationError, SecretStr, model_validator
from rich.console import Console
Expand All @@ -22,13 +25,35 @@
from tsticker.core.const import SERVICE_NAME, USERNAME
from tsticker.core.create import StickerPack, Emote

CURRENT_VERSION = metadata.version("tsticker")
PYPI_URL = "https://pypi.org/pypi/tsticker/json"

magika = Magika()
console = Console()
# 全局请求限制器
semaphore = Semaphore(20)
request_interval = 60 / 30 # 每个请求间隔时间为 60 秒 / 30 请求 = 2 秒


async def check_for_updates():
try:
response = requests.get(PYPI_URL)
if response.status_code == 200:
package_info = response.json()
latest_version = package_info['info']['version']

if latest_version != CURRENT_VERSION:
release_notes = package_info['releases'].get(latest_version, [])
release_info = release_notes[0] if release_notes else {}
description = release_info.get('comment_text', '')
click.echo(
f"INFO: tsticker {CURRENT_VERSION} is installed, while {latest_version} is available."
f"COMMENT: {description}" if description else ""
)
except Exception as e:
console.print(f"[bold green]Skipping update check: {type(e)}[/]")


async def limited_request(coro):
async with semaphore:
result = await coro
Expand Down Expand Up @@ -618,6 +643,9 @@ async def push():
pack, index_file, app = await upon_credentials()
if not pack or not index_file or not app:
return
# 检查仓库更新
await check_for_updates()
# 获取云端文件
with console.status("[bold yellow]Retrieving sticker...[/]", spinner='dots'):
try:
sticker_set = await limited_request(app.bot.get_sticker_set(pack.name))
Expand Down

0 comments on commit cbd9763

Please sign in to comment.