diff --git a/src/api.nim b/src/api.nim index e1d2232..9282523 100644 --- a/src/api.nim +++ b/src/api.nim @@ -2,7 +2,7 @@ import httpclient, asyncdispatch, htmlparser, times import sequtils, strutils, strformat, json, xmltree, uri import regex -import ./types, ./parser, ./parserutils +import ./types, ./parser, ./parserutils, ./formatters const agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" @@ -90,7 +90,7 @@ proc getVideo*(tweet: Tweet; token: string) {.async.} = let headers = newHttpHeaders({ "Accept": "application/json, text/javascript, */*; q=0.01", - "Referer": $(base / tweet.link), + "Referer": $(base / getLink(tweet)), "User-Agent": agent, "Authorization": auth, "x-guest-token": token @@ -138,7 +138,7 @@ proc getPoll*(tweet: Tweet) {.async.} = let headers = newHttpHeaders({ "Accept": cardAccept, - "Referer": $(base / tweet.link), + "Referer": $(base / getLink(tweet)), "User-Agent": agent, "Authority": "twitter.com", "Accept-Language": lang, diff --git a/src/formatters.nim b/src/formatters.nim index 122f2b4..2f60670 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -94,3 +94,6 @@ proc pageTitle*(page: string): string = proc getTime*(tweet: Tweet): string = tweet.time.format("d/M/yyyy', ' HH:mm:ss") + +proc getLink*(tweet: Tweet | Quote): string = + &"{tweet.profile.username}/status/{tweet.id}" diff --git a/src/parser.nim b/src/parser.nim index 591eb1d..ac26443 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -42,7 +42,6 @@ proc parseTweetProfile*(profile: XmlNode): Profile = proc parseQuote*(quote: XmlNode): Quote = result = Quote( id: quote.attr("data-item-id"), - link: quote.attr("href"), text: getQuoteText(quote) ) @@ -60,7 +59,6 @@ proc parseTweet*(node: XmlNode): Tweet = result = Tweet( id: tweet.attr("data-item-id"), - link: tweet.attr("data-permalink-path"), text: getTweetText(tweet), time: getTimestamp(tweet), shortTime: getShortTime(tweet), diff --git a/src/types.nim b/src/types.nim index a1e267b..dadb88c 100644 --- a/src/types.nim +++ b/src/types.nim @@ -57,7 +57,6 @@ type Quote* = object id*: string profile*: Profile - link*: string text*: string sensitive*: bool thumb*: Option[string] @@ -66,7 +65,6 @@ type Tweet* = ref object id*: string profile*: Profile - link*: string text*: string time*: Time shortTime*: string diff --git a/src/views/tweet.nimf b/src/views/tweet.nimf index 8087f5e..bcee4ab 100644 --- a/src/views/tweet.nimf +++ b/src/views/tweet.nimf @@ -23,7 +23,7 @@ ${linkUser(tweet.profile, class="username")} - ${tweet.shortTime} + ${tweet.shortTime} @@ -33,7 +33,7 @@ #let hasMedia = quote.thumb.isSome() or quote.sensitive