From 4971491dfe48d028e8456576088c438bd02d978f Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 18 Sep 2019 20:54:07 +0200 Subject: [PATCH] Options cleanup --- src/api/media.nim | 10 +++++----- src/api/search.nim | 4 ++-- src/api/timeline.nim | 2 +- src/cache.nim | 4 ++-- src/parser.nim | 10 +++++----- src/parserutils.nim | 8 ++++---- src/routes/rss.nim | 6 +++--- src/routes/timeline.nim | 12 ++++++------ 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/api/media.nim b/src/api/media.nim index 2b3b667..03c1a23 100644 --- a/src/api/media.nim +++ b/src/api/media.nim @@ -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 diff --git a/src/api/search.nim b/src/api/search.nim index 21cf9b8..6c8ce89 100644 --- a/src/api/search.nim +++ b/src/api/search.nim @@ -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"): diff --git a/src/api/timeline.nim b/src/api/timeline.nim index 1f56cb7..ae75245 100644 --- a/src/api/timeline.nim +++ b/src/api/timeline.nim @@ -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({ diff --git a/src/cache.nim b/src/cache.nim index ec4c1bd..f02b568 100644 --- a/src/cache.nim +++ b/src/cache.nim @@ -29,9 +29,9 @@ proc hasCachedProfile*(username: string): Option[Profile] = try: let p = Profile.getOne("lower(username) = ?", toLower(username)) doAssert not p.isOutdated - result = some(p) + result = some p except AssertionError, KeyError: - result = none(Profile) + result = none Profile proc getCachedProfile*(username, agent: string; force=false): Future[Profile] {.async.} = withDb: diff --git a/src/parser.nim b/src/parser.nim index 0285c10..90ff116 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -104,20 +104,20 @@ proc parseTweet*(node: XmlNode): Tweet = let by = tweet.selectText(".js-retweet-text > a > b") if by.len > 0: - result.retweet = some(Retweet( + result.retweet = some Retweet( by: stripText(by), id: tweet.attr("data-retweet-id") - )) + ) let quote = tweet.select(".QuoteTweet-innerContainer") if quote != nil: - result.quote = some(parseQuote(quote)) + result.quote = some parseQuote(quote) let tombstone = tweet.select(".Tombstone") if tombstone != nil: if "unavailable" in tombstone.innerText(): let quote = Quote(tombstone: getTombstone(node.selectText(".Tombstone-label"))) - result.quote = some(quote) + result.quote = some quote proc parseThread*(nodes: XmlNode): Thread = if nodes == nil: return @@ -234,7 +234,7 @@ proc parseCard*(card: var Card; node: XmlNode) = let image = node.select(".tcu-imageWrapper img") if image != nil: # workaround for issue 11713 - card.image = some(image.attr("data-src").replace("gname", "g&name")) + card.image = some image.attr("data-src").replace("gname", "g&name") if card.kind == liveEvent: card.text = card.title diff --git a/src/parserutils.nim b/src/parserutils.nim index 90ebd17..53be3c9 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -180,9 +180,9 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) = if player == nil: return if "gif" in player.attr("class"): - tweet.gif = some(getGif(player.select(".PlayableMedia-player"))) + tweet.gif = some getGif(player.select(".PlayableMedia-player")) elif "video" in player.attr("class"): - tweet.video = some(Video()) + tweet.video = some Video() proc getQuoteMedia*(quote: var Quote; node: XmlNode) = if node.select(".QuoteTweet--sensitive") != nil: @@ -209,7 +209,7 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) = cardType = cardType.split(":")[^1] if "poll" in cardType: - tweet.poll = some(Poll()) + tweet.poll = some Poll() return let cardDiv = node.select(".card2 > .js-macaw-cards-iframe-container") @@ -230,7 +230,7 @@ proc getTweetCard*(tweet: Tweet; node: XmlNode) = if n.attr("href") == cardUrl: card.url = n.attr("data-expanded-url") - tweet.card = some(card) + tweet.card = some card proc getMoreReplies*(node: XmlNode): int = let text = node.innerText().strip() diff --git a/src/routes/rss.nim b/src/routes/rss.nim index 58fb7de..7c99ab2 100644 --- a/src/routes/rss.nim +++ b/src/routes/rss.nim @@ -21,12 +21,12 @@ proc createRssRouter*(cfg: Config) = router rss: get "/@name/rss": cond '.' notin @"name" - respRss(await showRss(@"name", none(Query))) + respRss(await showRss(@"name", none Query)) get "/@name/replies/rss": cond '.' notin @"name" - respRss(await showRss(@"name", some(getReplyQuery(@"name")))) + respRss(await showRss(@"name", some getReplyQuery(@"name"))) get "/@name/media/rss": cond '.' notin @"name" - respRss(await showRss(@"name", some(getMediaQuery(@"name")))) + respRss(await showRss(@"name", some getMediaQuery(@"name"))) diff --git a/src/routes/timeline.nim b/src/routes/timeline.nim index 683c111..8b40507 100644 --- a/src/routes/timeline.nim +++ b/src/routes/timeline.nim @@ -47,7 +47,7 @@ proc fetchMultiTimeline*(names: seq[string]; after, agent: string; if q.isSome: get(q).fromUser = names else: - q = some(Query(kind: multi, fromUser: names, excludes: @["replies"])) + q = some Query(kind: multi, fromUser: names, excludes: @["replies"]) return await getSearch[Tweet](get(q), after, agent) @@ -79,25 +79,25 @@ proc createTimelineRouter*(cfg: Config) = get "/@name/?": cond '.' notin @"name" let rss = "/$1/rss" % @"name" - respTimeline(await showTimeline(@"name", @"after", none(Query), cookiePrefs(), + respTimeline(await showTimeline(@"name", @"after", none Query, cookiePrefs(), getPath(), cfg.title, rss)) get "/@name/search": cond '.' notin @"name" - let query = initQuery(@"filter", @"include", @"not", @"sep", @"text", @"name") - respTimeline(await showTimeline(@"name", @"after", some(query), + let query = some initQuery(@"filter", @"include", @"not", @"sep", @"text", @"name") + respTimeline(await showTimeline(@"name", @"after", query, cookiePrefs(), getPath(), cfg.title, "")) get "/@name/replies": cond '.' notin @"name" let rss = "/$1/replies/rss" % @"name" - respTimeline(await showTimeline(@"name", @"after", some(getReplyQuery(@"name")), + respTimeline(await showTimeline(@"name", @"after", some getReplyQuery(@"name"), cookiePrefs(), getPath(), cfg.title, rss)) get "/@name/media": cond '.' notin @"name" let rss = "/$1/media/rss" % @"name" - respTimeline(await showTimeline(@"name", @"after", some(getMediaQuery(@"name")), + respTimeline(await showTimeline(@"name", @"after", some getMediaQuery(@"name"), cookiePrefs(), getPath(), cfg.title, rss)) get "/@name/status/@id":