From 60986ecc8836392afa3fd585da5b5bffb26528bf Mon Sep 17 00:00:00 2001 From: Zed Date: Sun, 11 Aug 2019 23:24:02 +0200 Subject: [PATCH] Display media count above photo rail --- src/parser.nim | 3 ++- src/parserutils.nim | 4 ++++ src/types.nim | 1 + src/views/profile.nim | 10 +++++----- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/parser.nim b/src/parser.nim index 443b2e8..a0056d7 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -17,7 +17,8 @@ proc parseTimelineProfile*(node: XmlNode): Profile = userpic: node.getAvatar(".profile-picture img"), verified: isVerified(profile), protected: isProtected(profile), - banner: getTimelineBanner(node) + banner: getTimelineBanner(node), + media: getMediaCount(node) ) result.getProfileStats(node.select(".ProfileNav-list")) diff --git a/src/parserutils.nim b/src/parserutils.nim index 4052984..6de7bdf 100644 --- a/src/parserutils.nim +++ b/src/parserutils.nim @@ -114,6 +114,10 @@ proc getTimelineBanner*(node: XmlNode): string = if style.find(re"a:active \{\n +color: (#[A-Z0-9]+)", m): return style[m.group(0)[0]] +proc getMediaCount*(node: XmlNode): string = + let text = node.selectText(".PhotoRail-headingWithCount") + return text.stripText().split(" ")[0] + proc getProfileStats*(profile: var Profile; node: XmlNode) = for s in node.selectAll( ".ProfileNav-stat"): let text = s.attr("title").split(" ")[0] diff --git a/src/types.nim b/src/types.nim index ba68dcf..40a795c 100644 --- a/src/types.nim +++ b/src/types.nim @@ -21,6 +21,7 @@ db("cache.db", "", "", ""): followers*: string tweets*: string likes*: string + media*: string verified* {. dbType: "STRING", parseIt: parseBool(it.s) diff --git a/src/views/profile.nim b/src/views/profile.nim index eabc0fb..efb8105 100644 --- a/src/views/profile.nim +++ b/src/views/profile.nim @@ -45,16 +45,16 @@ proc renderProfileCard*(profile: Profile): VNode = renderStat(profile.following, "following") renderStat(profile.likes, "likes") -proc renderPhotoRail(username: string; photoRail: seq[GalleryPhoto]): VNode = +proc renderPhotoRail(profile: Profile; photoRail: seq[GalleryPhoto]): VNode = buildHtml(tdiv(class="photo-rail-card")): tdiv(class="photo-rail-header"): - a(href=(&"/{username}/media")): - text "🖼 Photos and videos" + a(href=(&"/{profile.username}/media")): + text &"🖼 {profile.media} Photos and videos" tdiv(class="photo-rail-grid"): for i, photo in photoRail: if i == 16: break - a(href=(&"/{username}/status/{photo.tweetId}"), + a(href=(&"/{profile.username}/status/{photo.tweetId}"), style={backgroundColor: photo.color}): genImg(photo.url & ":thumb") @@ -75,7 +75,7 @@ proc renderProfile*(profile: Profile; timeline: Timeline; tdiv(class="profile-tab"): renderProfileCard(profile) if photoRail.len > 0: - renderPhotoRail(profile.username, photoRail) + renderPhotoRail(profile, photoRail) tdiv(class="timeline-tab"): renderTimeline(timeline, profile.username, profile.protected)