Tweak /.tokens, add amount of limited accounts

This commit is contained in:
Zed 2023-08-22 03:43:18 +02:00
parent 5c08e6a774
commit 6e8744943f

View file

@ -19,6 +19,7 @@ proc getPoolJson*(): JsonNode =
list = newJObject() list = newJObject()
totalReqs = 0 totalReqs = 0
totalPending = 0 totalPending = 0
totalLimited = 0
reqsPerApi: Table[string, int] reqsPerApi: Table[string, int]
let now = epochTime().int let now = epochTime().int
@ -31,34 +32,40 @@ proc getPoolJson*(): JsonNode =
} }
for api in account.apis.keys: for api in account.apis.keys:
let obj = %*{} let
if account.apis[api].limited: apiStatus = account.apis[api]
obj["limited"] = %true obj = %*{}
if account.apis[api].reset > now.int: if apiStatus.limited:
obj["remaining"] = %account.apis[api].remaining 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 list[account.id]["apis"][$api] = obj
if "remaining" notin obj:
continue
let let
maxReqs = maxReqs =
case api case api
of Api.search: 50 of Api.search: 50
of Api.tweetDetail: 150
of Api.photoRail: 180 of Api.photoRail: 180
of Api.userTweets, Api.userTweetsAndReplies, Api.userMedia, of Api.userTweets, Api.userTweetsAndReplies, Api.userMedia,
Api.userRestId, Api.userScreenName, Api.userRestId, Api.userScreenName, Api.tweetResult,
Api.tweetDetail, Api.tweetResult,
Api.list, Api.listTweets, Api.listMembers, Api.listBySlug: 500 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 reqsPerApi[$api] = reqsPerApi.getOrDefault($api, 0) + reqs
totalReqs.inc(reqs) totalReqs.inc(reqs)
return %*{ return %*{
"amount": accountPool.len, "amount": accountPool.len,
"limited": totalLimited,
"requests": totalReqs, "requests": totalReqs,
"pending": totalPending, "pending": totalPending,
"apis": reqsPerApi, "apis": reqsPerApi,