From 6e8744943f9c47cbc7150785a86fa05a18d7b98b Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 22 Aug 2023 03:43:18 +0200 Subject: [PATCH] Tweak /.tokens, add amount of limited accounts --- src/tokens.nim | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/tokens.nim b/src/tokens.nim index f16a816..5582a51 100644 --- a/src/tokens.nim +++ b/src/tokens.nim @@ -19,6 +19,7 @@ proc getPoolJson*(): JsonNode = list = newJObject() totalReqs = 0 totalPending = 0 + totalLimited = 0 reqsPerApi: Table[string, int] let now = epochTime().int @@ -31,34 +32,40 @@ proc getPoolJson*(): JsonNode = } for api in account.apis.keys: - let obj = %*{} - if account.apis[api].limited: - obj["limited"] = %true + let + apiStatus = account.apis[api] + obj = %*{} - if account.apis[api].reset > now.int: - obj["remaining"] = %account.apis[api].remaining + if apiStatus.limited: + obj["limited"] = %true + inc totalLimited + + if apiStatus.reset > now.int: + obj["remaining"] = %apiStatus.remaining + + if "remaining" notin obj and not apiStatus.limited: + continue list[account.id]["apis"][$api] = obj - if "remaining" notin obj: - continue - let maxReqs = case api of Api.search: 50 + of Api.tweetDetail: 150 of Api.photoRail: 180 of Api.userTweets, Api.userTweetsAndReplies, Api.userMedia, - Api.userRestId, Api.userScreenName, - Api.tweetDetail, Api.tweetResult, + Api.userRestId, Api.userScreenName, Api.tweetResult, Api.list, Api.listTweets, Api.listMembers, Api.listBySlug: 500 - reqs = maxReqs - account.apis[api].remaining + of Api.userSearch: 900 + reqs = maxReqs - apiStatus.remaining reqsPerApi[$api] = reqsPerApi.getOrDefault($api, 0) + reqs totalReqs.inc(reqs) return %*{ "amount": accountPool.len, + "limited": totalLimited, "requests": totalReqs, "pending": totalPending, "apis": reqsPerApi,