mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-23 03:15:40 +00:00
Improve tweet selectors
This commit is contained in:
parent
02fcd7b880
commit
7d2fa15676
|
@ -83,8 +83,7 @@ proc parseTweet*(node: XmlNode): Tweet =
|
|||
|
||||
proc parseTweets*(node: XmlNode): Tweets =
|
||||
if node.isNil or node.kind == xnText: return
|
||||
for n in node.selectAll(".stream-item"):
|
||||
result.add parseTweet(n)
|
||||
node.selectAll(".stream-item").map(parseTweet)
|
||||
|
||||
proc parseConversation*(node: XmlNode): Conversation =
|
||||
result = Conversation(
|
||||
|
@ -92,12 +91,13 @@ proc parseConversation*(node: XmlNode): Conversation =
|
|||
before: parseTweets(node.select(".in-reply-to"))
|
||||
)
|
||||
|
||||
let replies = node.select(".replies-to")
|
||||
let replies = node.select(".replies-to", ".stream-items")
|
||||
if replies.isNil: return
|
||||
|
||||
result.after = parseTweets(replies.select(".ThreadedConversation--selfThread"))
|
||||
|
||||
for reply in replies.select(".stream-items"):
|
||||
for reply in replies.filterIt(it.kind != xnText):
|
||||
if "selfThread" in reply.attr("class"):
|
||||
result.after = parseTweets(reply.select(".stream-items"))
|
||||
else:
|
||||
result.replies.add parseTweets(reply)
|
||||
|
||||
proc parseVideo*(node: JsonNode): Video =
|
||||
|
|
|
@ -16,6 +16,11 @@ proc select*(node: XmlNode; selector: string): XmlNode =
|
|||
let nodes = node.selectAll(selector)
|
||||
if nodes.len > 0: nodes[0] else: nil
|
||||
|
||||
proc select*(node: XmlNode; parent, child: string): XmlNode =
|
||||
let parentNode = node.select(parent)
|
||||
if parentNode.isNil(): return
|
||||
result = parentNode.select(child)
|
||||
|
||||
proc getAttr*(node: XmlNode; attr: string; default=""): string =
|
||||
if node.isNil or node.attrs.isNil: return default
|
||||
return node.attrs.getOrDefault(attr)
|
||||
|
|
Loading…
Reference in a new issue