Use old user endpoint to avoid graphql rate limits
This commit is contained in:
parent
39863703b3
commit
74534e8fef
|
@ -32,6 +32,12 @@ proc getListMembers*(list: List; after=""): Future[Result[Profile]] {.async.} =
|
|||
url = listMembers ? ps
|
||||
result = parseListMembers(await fetch(url, oldApi=true), after)
|
||||
|
||||
proc getProfile*(username: string): Future[Profile] {.async.} =
|
||||
let
|
||||
ps = genParams({"screen_name": username})
|
||||
url = userLookup ? ps
|
||||
result = parseUserShow(await fetch(url, oldApi=true), username)
|
||||
|
||||
proc getTimeline*(id: string; after=""; replies=false): Future[Timeline] {.async.} =
|
||||
let
|
||||
ps = genParams({"userId": id, "include_tweet_replies": $replies}, after)
|
||||
|
|
|
@ -13,6 +13,7 @@ const
|
|||
mediaTimeline* = timelineApi / "media"
|
||||
listTimeline* = timelineApi / "list.json"
|
||||
listMembers* = api / "1.1/lists/members.json"
|
||||
userLookup* = api / "1.1/users/show.json"
|
||||
tweet* = timelineApi / "conversation"
|
||||
search* = api / "2/search/adaptive.json"
|
||||
|
||||
|
|
|
@ -27,6 +27,16 @@ proc parseProfile(js: JsonNode; id=""): Profile =
|
|||
|
||||
result.expandProfileEntities(js)
|
||||
|
||||
proc parseUserShow*(js: JsonNode; username: string): Profile =
|
||||
if js == nil: return
|
||||
with error, js{"errors"}:
|
||||
result = Profile(username: username)
|
||||
if parseError(error) == suspended:
|
||||
result.suspended = true
|
||||
return
|
||||
|
||||
result = parseProfile(js)
|
||||
|
||||
proc parseGraphProfile*(js: JsonNode; username: string): Profile =
|
||||
if js == nil: return
|
||||
with error, js{"errors"}:
|
||||
|
@ -301,6 +311,9 @@ proc parseConversation*(js: JsonNode; tweetId: string): Conversation =
|
|||
let global = parseGlobalObjects(? js)
|
||||
|
||||
let instructions = ? js{"timeline", "instructions"}
|
||||
if instructions.len == 0:
|
||||
return
|
||||
|
||||
for e in instructions[0]{"addEntries", "entries"}:
|
||||
let entry = e{"entryId"}.getStr
|
||||
if "tweet" in entry:
|
||||
|
|
|
@ -79,7 +79,7 @@ proc getCachedProfile*(username: string; fetch=true): Future[Profile] {.async.}
|
|||
if prof != redisNil:
|
||||
result = prof.to(Profile)
|
||||
else:
|
||||
result = await getGraphProfile(username)
|
||||
result = await getProfile(username)
|
||||
if result.id.len > 0:
|
||||
await cache(result)
|
||||
|
||||
|
|
Loading…
Reference in New Issue