Detect suspended accounts

This commit is contained in:
Zed 2020-04-14 23:56:31 +02:00
commit 8a6978cf74
8 changed files with 38 additions and 6 deletions

View file

@ -1,4 +1,4 @@
import asyncdispatch, strutils, uri
import asyncdispatch, strutils, uri, httpclient, json, xmltree, htmlparser
import ".."/[types, parser]
import utils, consts, media
@ -7,11 +7,21 @@ proc getTweet*(username, id, after, agent: string): Future[Conversation] {.async
let
headers = genHeaders({
"pragma": "no-cache",
"x-previous-page-name": "profile"
"x-previous-page-name": "profile",
"accept": htmlAccept
}, agent, base, xml=true)
url = base / username / tweetUrl / id ? {"max_position": after}
html = await fetchHtml(url, headers)
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
if html == nil: return