Refactor api code

This commit is contained in:
Zed
2019-09-06 03:37:12 +02:00
parent 014f01bf88
commit 43bf6735d4
13 changed files with 414 additions and 397 deletions

31
src/api/tweet.nim Normal file
View File

@@ -0,0 +1,31 @@
import httpclient, asyncdispatch, strutils, uri
import ".."/[types, parser]
import utils, consts, media
proc getTweet*(username, id, agent: string): Future[Conversation] {.async.} =
let headers = newHttpHeaders({
"Accept": jsonAccept,
"Referer": $base,
"User-Agent": agent,
"X-Twitter-Active-User": "yes",
"X-Requested-With": "XMLHttpRequest",
"Accept-Language": lang,
"pragma": "no-cache",
"x-previous-page-name": "profile"
})
let
url = base / username / tweetUrl / id
html = await fetchHtml(url, headers)
if html == nil: return
result = parseConversation(html)
let
vidsFut = getConversationVideos(result, agent)
pollFut = getConversationPolls(result, agent)
cardFut = getConversationCards(result, agent)
await all(vidsFut, pollFut, cardFut)