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