Cleanup
This commit is contained in:
@@ -4,7 +4,8 @@ import strutils, json, xmltree, uri
|
||||
import ".."/[types, parser, parserutils, query]
|
||||
import utils, consts, timeline
|
||||
|
||||
proc getResult[T](json: JsonNode; query: Query; after: string): Result[T] =
|
||||
proc getResult*[T](json: JsonNode; query: Query; after: string): Result[T] =
|
||||
if json == nil: return Result[T](beginning: true, query: query)
|
||||
Result[T](
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
maxId: json.getOrDefault("max_position").getStr(""),
|
||||
@@ -46,11 +47,11 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn
|
||||
|
||||
result = getResult[T](json, query, after)
|
||||
if not json.hasKey("items_html"): return
|
||||
let html = parseHtml(json["items_html"].to(string))
|
||||
|
||||
when T is Tweet:
|
||||
result = await finishTimeline(json, query, after, agent)
|
||||
elif T is Profile:
|
||||
result.hasMore = json["items_html"].to(string) != "\n"
|
||||
for p in html.selectAll(".js-stream-item"):
|
||||
let html = json["items_html"].to(string)
|
||||
result.hasMore = html != "\n"
|
||||
for p in parseHtml(html).selectAll(".js-stream-item"):
|
||||
result.content.add parsePopupProfile(p, ".ProfileCard")
|
||||
|
||||
@@ -2,18 +2,11 @@ import httpclient, asyncdispatch, htmlparser
|
||||
import sequtils, strutils, json, xmltree, uri
|
||||
|
||||
import ".."/[types, parser, parserutils, formatters, query]
|
||||
import utils, consts, media
|
||||
import utils, consts, media, search
|
||||
|
||||
proc finishTimeline*(json: JsonNode; query: Query; after, agent: string): Future[Timeline] {.async.} =
|
||||
if json == nil: return Timeline(beginning: true, query: query)
|
||||
|
||||
result = Timeline(
|
||||
hasMore: json["has_more_items"].to(bool),
|
||||
maxId: json.getOrDefault("max_position").getStr(""),
|
||||
minId: json.getOrDefault("min_position").getStr("").cleanPos(),
|
||||
query: query,
|
||||
beginning: after.len == 0
|
||||
)
|
||||
result = getResult[Tweet](json, query, after)
|
||||
if json == nil: return
|
||||
|
||||
if json["new_latent_count"].to(int) == 0: return
|
||||
if not json.hasKey("items_html"): return
|
||||
|
||||
Reference in New Issue
Block a user