mirror of
https://github.com/zedeus/nitter.git
synced 2025-12-06 03:55:36 -05:00
Cleanup
This commit is contained in:
17
src/auth.nim
17
src/auth.nim
@@ -7,20 +7,6 @@ import experimental/parser/session
|
|||||||
const
|
const
|
||||||
maxConcurrentReqs = 2
|
maxConcurrentReqs = 2
|
||||||
hourInSeconds = 60 * 60
|
hourInSeconds = 60 * 60
|
||||||
apiMaxReqs: Table[Api, int] = {
|
|
||||||
Api.search: 50,
|
|
||||||
Api.tweetDetail: 500,
|
|
||||||
Api.userTweets: 500,
|
|
||||||
Api.userTweetsAndReplies: 500,
|
|
||||||
Api.userMedia: 500,
|
|
||||||
Api.userRestId: 500,
|
|
||||||
Api.userScreenName: 500,
|
|
||||||
Api.tweetResult: 500,
|
|
||||||
Api.list: 500,
|
|
||||||
Api.listTweets: 500,
|
|
||||||
Api.listMembers: 500,
|
|
||||||
Api.listBySlug: 500
|
|
||||||
}.toTable
|
|
||||||
|
|
||||||
var
|
var
|
||||||
sessionPool: seq[Session]
|
sessionPool: seq[Session]
|
||||||
@@ -71,8 +57,7 @@ proc getSessionPoolHealth*(): JsonNode =
|
|||||||
for api in session.apis.keys:
|
for api in session.apis.keys:
|
||||||
let
|
let
|
||||||
apiStatus = session.apis[api]
|
apiStatus = session.apis[api]
|
||||||
limit = if apiStatus.limit > 0: apiStatus.limit else: apiMaxReqs.getOrDefault(api, 0)
|
reqs = apiStatus.limit - apiStatus.remaining
|
||||||
reqs = limit - apiStatus.remaining
|
|
||||||
|
|
||||||
# no requests made with this session and endpoint since the limit reset
|
# no requests made with this session and endpoint since the limit reset
|
||||||
if apiStatus.reset < now:
|
if apiStatus.reset < now:
|
||||||
|
|||||||
@@ -72,21 +72,3 @@ proc parseHook*(s: string; i: var int; v: var User) =
|
|||||||
var u: RawUser
|
var u: RawUser
|
||||||
parseHook(s, i, u)
|
parseHook(s, i, u)
|
||||||
v = toUser u
|
v = toUser u
|
||||||
|
|
||||||
proc parseUser*(json: string; username=""): User =
|
|
||||||
handleErrors:
|
|
||||||
case error.code
|
|
||||||
of suspended: return User(username: username, suspended: true)
|
|
||||||
of userNotFound: return
|
|
||||||
else: echo "[error - parseUser]: ", error
|
|
||||||
|
|
||||||
result = json.fromJson(User)
|
|
||||||
|
|
||||||
proc parseUsers*(json: string; after=""): Result[User] =
|
|
||||||
result = Result[User](beginning: after.len == 0)
|
|
||||||
|
|
||||||
# starting with '{' means it's an error
|
|
||||||
if json[0] == '[':
|
|
||||||
let raw = json.fromJson(seq[RawUser])
|
|
||||||
for user in raw:
|
|
||||||
result.content.add user.toUser
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
import std/tables
|
|
||||||
from ../../types import User
|
|
||||||
|
|
||||||
type
|
|
||||||
Search* = object
|
|
||||||
globalObjects*: GlobalObjects
|
|
||||||
timeline*: Timeline
|
|
||||||
|
|
||||||
GlobalObjects = object
|
|
||||||
users*: Table[string, User]
|
|
||||||
|
|
||||||
Timeline = object
|
|
||||||
instructions*: seq[Instructions]
|
|
||||||
|
|
||||||
Instructions = object
|
|
||||||
addEntries*: tuple[entries: seq[Entry]]
|
|
||||||
|
|
||||||
Entry = object
|
|
||||||
entryId*: string
|
|
||||||
content*: tuple[operation: Operation]
|
|
||||||
|
|
||||||
Operation = object
|
|
||||||
cursor*: tuple[value, cursorType: string]
|
|
||||||
Reference in New Issue
Block a user