nitter/src/api/tweet.nim

33 lines
948 B
Nim
Raw Normal View History

2020-04-14 23:56:31 +02:00
import asyncdispatch, strutils, uri, httpclient, json, xmltree, htmlparser
2019-09-06 03:37:12 +02:00
import ".."/[types, parser]
import utils, consts, media
proc getTweet*(username, id, after, agent: string): Future[Conversation] {.async.} =
2019-09-06 03:37:12 +02:00
let
2019-10-02 10:13:17 +02:00
headers = genHeaders({
"pragma": "no-cache",
2020-04-14 23:56:31 +02:00
"x-previous-page-name": "profile",
"accept": htmlAccept
2020-01-22 14:01:27 +01:00
}, agent, base, xml=true)
2019-10-02 10:13:17 +02:00
url = base / username / tweetUrl / id ? {"max_position": after}
2020-04-14 23:56:31 +02:00
newClient()
var html: XmlNode
try:
let resp = await client.get($url)
if resp.code == Http403 and "suspended" in (await resp.body):
return Conversation(tweet: Tweet(tombstone: "User has been suspended"))
html = parseHtml(await resp.body)
except:
discard
2019-09-06 03:37:12 +02:00
if html == nil: return
result = parseConversation(html, after)
2019-09-06 03:37:12 +02:00
2019-10-02 22:28:53 +02:00
await all(getConversationVideos(result, agent),
getConversationCards(result, agent),
getConversationPolls(result, agent))