From 9dc4b240e72c05d2778d11aed892c92dc8a88cd4 Mon Sep 17 00:00:00 2001 From: Zed Date: Thu, 27 Jun 2019 21:48:59 +0200 Subject: [PATCH] Fix tweet tags being shown as unavailable tweets --- src/api.nim | 5 +++-- src/parser.nim | 4 +++- src/parserutils.nim | 6 ++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api.nim b/src/api.nim index 2982ddf..af47462 100644 --- a/src/api.nim +++ b/src/api.nim @@ -188,10 +188,11 @@ proc getTimeline*(username: string; after=""): Future[Timeline] {.async.} = minId: json.getOrDefault("min_position").getStr(""), ) - if json["new_latent_count"].to(int) == 0: - return + if json["new_latent_count"].to(int) == 0: return + if not json.hasKey("items_html"): return let html = parseHtml(json["items_html"].to(string)) + result.tweets = parseTweets(html) await getVideos(result.tweets) diff --git a/src/parser.nim b/src/parser.nim index 8a2b308..9887e26 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -83,7 +83,9 @@ proc parseTweet*(node: XmlNode): Tweet = proc parseTweets*(node: XmlNode): Tweets = if node == nil or node.kind == xnText: return - node.selectAll(".stream-item").map(parseTweet) + for n in node.selectAll(".stream-item"): + if "account" notin n.child("div").attr("class"): + result.add parseTweet(n) proc parseConversation*(node: XmlNode): Conversation = result = Conversation( diff --git a/src/parserutils.nim b/src/parserutils.nim index a32ad49..44ed652 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -140,8 +140,7 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) = tweet.photos.add photo.attrs["data-image-url"] let player = node.select(".PlayableMedia") - if player == nil: - return + if player == nil: return if "gif" in player.attr("class"): tweet.gif = some(getGif(player.select(".PlayableMedia-player"))) @@ -149,8 +148,7 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) = tweet.video = some(Video()) proc getQuoteMedia*(quote: var Quote; node: XmlNode) = - let sensitive = node.select(".QuoteTweet--sensitive") - if sensitive != nil: + if node.select(".QuoteTweet--sensitive") != nil: quote.sensitive = true return