Explorar el Código

Display media count above photo rail

Zed hace 7 años
padre
commit
60986ecc88
Se han modificado 4 ficheros con 12 adiciones y 6 borrados
  1. 2 1
      src/parser.nim
  2. 4 0
      src/parserutils.nim
  3. 1 0
      src/types.nim
  4. 5 5
      src/views/profile.nim

+ 2 - 1
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"))

+ 4 - 0
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]

+ 1 - 0
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)

+ 5 - 5
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)