Options cleanup

This commit is contained in:
Zed
2019-09-18 20:54:07 +02:00
parent 4c748b61a5
commit 4971491dfe
8 changed files with 28 additions and 28 deletions

View File

@@ -89,10 +89,10 @@ proc getVideoFetch(tweet: Tweet; agent, token: string) {.async.} =
return
if tweet.card.isNone:
tweet.video = some(parseVideo(json, tweet.id))
tweet.video = some parseVideo(json, tweet.id)
else:
get(tweet.card).video = some(parseVideo(json, tweet.id))
tweet.video = none(Video)
get(tweet.card).video = some parseVideo(json, tweet.id)
tweet.video = none Video
tokenUses.inc
proc getVideoVar(tweet: Tweet): var Option[Video] =
@@ -104,7 +104,7 @@ proc getVideoVar(tweet: Tweet): var Option[Video] =
proc getVideo*(tweet: Tweet; agent, token: string; force=false) {.async.} =
withCustomDb("cache.db", "", "", ""):
try:
getVideoVar(tweet) = some(Video.getOne("videoId = ?", tweet.id))
getVideoVar(tweet) = some Video.getOne("videoId = ?", tweet.id)
except KeyError:
await getVideoFetch(tweet, agent, token)
var video = getVideoVar(tweet)
@@ -126,7 +126,7 @@ proc getPoll*(tweet: Tweet; agent: string) {.async.} =
let html = await fetchHtml(url, headers)
if html == nil: return
tweet.poll = some(parsePoll(html))
tweet.poll = some parsePoll(html)
proc getCard*(tweet: Tweet; agent: string) {.async.} =
if tweet.card.isNone(): return

View File

@@ -9,7 +9,7 @@ proc getResult[T](json: JsonNode; query: Query; after: string): Result[T] =
hasMore: json["has_more_items"].to(bool),
maxId: json.getOrDefault("max_position").getStr(""),
minId: json.getOrDefault("min_position").getStr("").cleanPos(),
query: query.some,
query: some query,
beginning: after.len == 0
)
@@ -49,7 +49,7 @@ proc getSearch*[T](query: Query; after, agent: string): Future[Result[T]] {.asyn
let html = parseHtml(json["items_html"].to(string))
when T is Tweet:
result = await finishTimeline(json, some(query), after, agent)
result = await finishTimeline(json, some query, after, agent)
elif T is Profile:
result.hasMore = json["items_html"].to(string) != "\n"
for p in html.selectAll(".js-stream-item"):

View File

@@ -49,7 +49,7 @@ proc getTimeline*(username, after, agent: string): Future[Timeline] {.async.} =
params.add {"max_position": after}
let json = await fetchJson(base / (timelineUrl % username) ? params, headers)
result = await finishTimeline(json, none(Query), after, agent)
result = await finishTimeline(json, none Query, after, agent)
proc getProfileAndTimeline*(username, agent, after: string): Future[(Profile, Timeline)] {.async.} =
let headers = newHttpHeaders({