Generate tweet links

This commit is contained in:
Zed 2019-07-01 23:14:36 +02:00
parent 04dbd07959
commit 9b07199901
5 changed files with 8 additions and 9 deletions

View File

@ -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,

View File

@ -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}"

View File

@ -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),

View File

@ -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

View File

@ -23,7 +23,7 @@
${linkUser(tweet.profile, class="username")}
</div>
<span class="heading-right">
<a href="${tweet.link}" title="${tweet.getTime()}">${tweet.shortTime}</a>
<a href="${getLink(tweet)}" title="${tweet.getTime()}">${tweet.shortTime}</a>
</span>
</div>
</div>
@ -33,7 +33,7 @@
#let hasMedia = quote.thumb.isSome() or quote.sensitive
<div class="quote">
<div class="quote-container">
<a class="quote-link" href="${quote.link}"></a>
<a class="quote-link" href="${getLink(quote)}"></a>
#if hasMedia:
<div class="quote-media-container">
<div class="quote-media">