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 sequtils, strutils, strformat, json, xmltree, uri
import regex import regex
import ./types, ./parser, ./parserutils import ./types, ./parser, ./parserutils, ./formatters
const 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" 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({ let headers = newHttpHeaders({
"Accept": "application/json, text/javascript, */*; q=0.01", "Accept": "application/json, text/javascript, */*; q=0.01",
"Referer": $(base / tweet.link), "Referer": $(base / getLink(tweet)),
"User-Agent": agent, "User-Agent": agent,
"Authorization": auth, "Authorization": auth,
"x-guest-token": token "x-guest-token": token
@ -138,7 +138,7 @@ proc getPoll*(tweet: Tweet) {.async.} =
let headers = newHttpHeaders({ let headers = newHttpHeaders({
"Accept": cardAccept, "Accept": cardAccept,
"Referer": $(base / tweet.link), "Referer": $(base / getLink(tweet)),
"User-Agent": agent, "User-Agent": agent,
"Authority": "twitter.com", "Authority": "twitter.com",
"Accept-Language": lang, "Accept-Language": lang,

View File

@ -94,3 +94,6 @@ proc pageTitle*(page: string): string =
proc getTime*(tweet: Tweet): string = proc getTime*(tweet: Tweet): string =
tweet.time.format("d/M/yyyy', ' HH:mm:ss") 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 = proc parseQuote*(quote: XmlNode): Quote =
result = Quote( result = Quote(
id: quote.attr("data-item-id"), id: quote.attr("data-item-id"),
link: quote.attr("href"),
text: getQuoteText(quote) text: getQuoteText(quote)
) )
@ -60,7 +59,6 @@ proc parseTweet*(node: XmlNode): Tweet =
result = Tweet( result = Tweet(
id: tweet.attr("data-item-id"), id: tweet.attr("data-item-id"),
link: tweet.attr("data-permalink-path"),
text: getTweetText(tweet), text: getTweetText(tweet),
time: getTimestamp(tweet), time: getTimestamp(tweet),
shortTime: getShortTime(tweet), shortTime: getShortTime(tweet),

View File

@ -57,7 +57,6 @@ type
Quote* = object Quote* = object
id*: string id*: string
profile*: Profile profile*: Profile
link*: string
text*: string text*: string
sensitive*: bool sensitive*: bool
thumb*: Option[string] thumb*: Option[string]
@ -66,7 +65,6 @@ type
Tweet* = ref object Tweet* = ref object
id*: string id*: string
profile*: Profile profile*: Profile
link*: string
text*: string text*: string
time*: Time time*: Time
shortTime*: string shortTime*: string

View File

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