mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47c83be1b5 | |||
| 6c0e092f51 | |||
| 04b9cd9eae | |||
|
|
61b5fcb137 |
@@ -1,5 +1,5 @@
|
|||||||
from asyncio import Lock
|
from asyncio import Lock
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import ClassVar
|
from typing import ClassVar
|
||||||
from weakref import WeakValueDictionary
|
from weakref import WeakValueDictionary
|
||||||
|
|
||||||
@@ -9,12 +9,15 @@ from nonebot.log import logger
|
|||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
from ....config.config import config
|
from ....config.config import config
|
||||||
|
from ....utils.limit import limit
|
||||||
from ....utils.request import Request
|
from ....utils.request import Request
|
||||||
from .schemas.base import FailedModel, SuccessModel
|
from .schemas.base import FailedModel, SuccessModel
|
||||||
|
|
||||||
UTC = timezone.utc
|
UTC = timezone.utc
|
||||||
|
|
||||||
|
|
||||||
request = Request(config.tetris.proxy.tetrio or config.tetris.proxy.main)
|
request = Request(config.tetris.proxy.tetrio or config.tetris.proxy.main)
|
||||||
|
request.request = limit(timedelta(seconds=1))(request.request) # type: ignore[method-assign]
|
||||||
|
|
||||||
|
|
||||||
class Cache:
|
class Cache:
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from nonebot_plugin_orm import get_session
|
|||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
from ....utils.exception import RequestError
|
from ....utils.exception import RequestError
|
||||||
from ....utils.limit import limit
|
|
||||||
from ....utils.retry import retry
|
from ....utils.retry import retry
|
||||||
from .. import alc
|
from .. import alc
|
||||||
from .. import command as base_command
|
from .. import command as base_command
|
||||||
@@ -84,11 +83,11 @@ def find_special_player(
|
|||||||
@scheduler.scheduled_job('cron', hour='0,6,12,18', minute=0)
|
@scheduler.scheduled_job('cron', hour='0,6,12,18', minute=0)
|
||||||
async def get_tetra_league_data() -> None:
|
async def get_tetra_league_data() -> None:
|
||||||
x_session_id = uuid4()
|
x_session_id = uuid4()
|
||||||
limit_by = retry(max_attempts=10, exception_type=RequestError)(limit(timedelta(seconds=1))(by))
|
retry_by = retry(max_attempts=10, exception_type=RequestError)(by)
|
||||||
prisecter = P(pri=9007199254740991, sec=9007199254740991, ter=9007199254740991) # * from ch.tetr.io
|
prisecter = P(pri=9007199254740991, sec=9007199254740991, ter=9007199254740991) # * from ch.tetr.io
|
||||||
results: list[BySuccessModel] = []
|
results: list[BySuccessModel] = []
|
||||||
while True:
|
while True:
|
||||||
model = await limit_by('league', Parameter(after=prisecter.to_prisecter(), limit=100), x_session_id)
|
model = await retry_by('league', Parameter(after=prisecter.to_prisecter(), limit=100), x_session_id)
|
||||||
prisecter = model.data.entries[-1].p
|
prisecter = model.data.entries[-1].p
|
||||||
results.append(model)
|
results.append(model)
|
||||||
if len(model.data.entries) < 100: # 分页值 # noqa: PLR2004
|
if len(model.data.entries) < 100: # 分页值 # noqa: PLR2004
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def limit(limit: timedelta) -> Callable[[Callable[P, Coroutine[Any, Any, T]]], C
|
|||||||
nonlocal last_call
|
nonlocal last_call
|
||||||
async with lock:
|
async with lock:
|
||||||
if (diff := (time() - last_call)) < limit_seconds:
|
if (diff := (time() - last_call)) < limit_seconds:
|
||||||
logger.debug(f'request limit {(limit_time:=limit_seconds-diff)}s')
|
logger.debug(f'func: {func.__name__} trigger limit, wait {(limit_time:=limit_seconds-diff):.3f}s')
|
||||||
await sleep(limit_time)
|
await sleep(limit_time)
|
||||||
last_call = time()
|
last_call = time()
|
||||||
return await func(*args, **kwargs)
|
return await func(*args, **kwargs)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = 'nonebot-plugin-tetris-stats'
|
name = 'nonebot-plugin-tetris-stats'
|
||||||
version = "1.5.4"
|
version = "1.5.5"
|
||||||
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
|
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
|
||||||
authors = ['scdhh <wallfjjd@gmail.com>']
|
authors = ['scdhh <wallfjjd@gmail.com>']
|
||||||
readme = 'README.md'
|
readme = 'README.md'
|
||||||
|
|||||||
Reference in New Issue
Block a user