Add support for loading more tweet replies

This commit is contained in:
Zed
2019-09-24 15:39:04 +02:00
parent 14e544500d
commit 9038645bc1
9 changed files with 44 additions and 22 deletions

View File

@@ -35,12 +35,12 @@ macro genMediaGet(media: untyped; token=false) =
futs.add `single`(convo.tweet, agent, token)
futs.add `multi`(convo.before, agent, token=token)
futs.add `multi`(convo.after, agent, token=token)
futs.add convo.replies.mapIt(`multi`(it, agent, token=token))
futs.add convo.replies.content.mapIt(`multi`(it, agent, token=token))
else:
futs.add `single`(convo.tweet, agent)
futs.add `multi`(convo.before, agent)
futs.add `multi`(convo.after, agent)
futs.add convo.replies.mapIt(`multi`(it, agent))
futs.add convo.replies.content.mapIt(`multi`(it, agent))
await all(futs)
proc getGuestToken(agent: string; force=false): Future[string] {.async.} =

View File

@@ -7,9 +7,9 @@ import utils, consts, timeline
proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] =
if json == nil: return Result[T](beginning: true, query: query)
Result[T](
hasMore: json.getOrDefault("has_more_items").getBool(false),
maxId: json.getOrDefault("max_position").getStr(""),
minId: json.getOrDefault("min_position").getStr("").cleanPos(),
hasMore: json{"has_more_items"}.getBool(false),
maxId: json{"max_position"}.getStr(""),
minId: json{"min_position"}.getStr("").cleanPos(),
query: query,
beginning: after.len == 0
)

View File

@@ -3,7 +3,7 @@ import httpclient, asyncdispatch, strutils, uri
import ".."/[types, parser]
import utils, consts, media
proc getTweet*(username, id, agent: string): Future[Conversation] {.async.} =
proc getTweet*(username, id, after, agent: string): Future[Conversation] {.async.} =
let headers = newHttpHeaders({
"Accept": jsonAccept,
"Referer": $base,
@@ -11,17 +11,17 @@ proc getTweet*(username, id, agent: string): Future[Conversation] {.async.} =
"X-Twitter-Active-User": "yes",
"X-Requested-With": "XMLHttpRequest",
"Accept-Language": lang,
"pragma": "no-cache",
"x-previous-page-name": "profile"
"Pragma": "no-cache",
"X-Previous-Page-Name": "profile"
})
let
url = base / username / tweetUrl / id
url = base / username / tweetUrl / id ? {"max_position": after}
html = await fetchHtml(url, headers)
if html == nil: return
result = parseConversation(html)
result = parseConversation(html, after)
let
vidsFut = getConversationVideos(result, agent)