diff --git a/src/api.nim b/src/api.nim index f4b249e..ab03697 100644 --- a/src/api.nim +++ b/src/api.nim @@ -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) diff --git a/src/consts.nim b/src/consts.nim index 246f020..2846d47 100644 --- a/src/consts.nim +++ b/src/consts.nim @@ -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" diff --git a/src/parser.nim b/src/parser.nim index 67fa0c2..58abc55 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -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: diff --git a/src/redis_cache.nim b/src/redis_cache.nim index 04c7e23..8eb3bcb 100644 --- a/src/redis_cache.nim +++ b/src/redis_cache.nim @@ -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)