Add initial CGI to parse comments given a subreddit and comment id. - gophercgis - Collection of gopher CGI/DCGI for geomyidae
(HTM) hg clone https://bitbucket.org/iamleot/gophercgis
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) changeset b0f380778f414b22818a7e5b2e56359e4f5c0a69
(DIR) parent b655e2a0f3bc6ebb86bbbf913266c1cc65a525b1
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Wed, 8 Aug 2018 03:50:12
Add initial CGI to parse comments given a subreddit and comment id.
Diffstat:
reddit/c.dcgi | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
---
diff -r b655e2a0f3bc -r b0f380778f41 reddit/c.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reddit/c.dcgi Wed Aug 08 03:50:12 2018 +0200
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+case "$2" in
+*/*)
+ subreddit="${2%%/*}"
+ id="${2##*/}"
+ ;;
+esac
+
+ua=""
+url="https://www.reddit.com/r/${subreddit}/comments/${id}/.json"
+
+/usr/pkg/bin/curl -A "${ua}" -s "${url}" |
+/usr/pkg/bin/jq -r '
+( .[0] | .data.children[] | .data |
+ "t",
+ "[h|\(.subreddit_name_prefixed | gsub("\\|"; "\\|") ) - " +
+ "\(.title | gsub("\\|"; "\\|") )|" +
+ "URL:\(.url | gsub("\\|"; "\\|"))|server|port]",
+ "t\(.author) \( .created_utc | strftime("%F %H:%M") )",
+ "tScore: \(.score)",
+ "tComments: \(.num_comments)",
+ "t" ),
+( .[1] | .data.children[] | .data | "tTODO: parse comments" )
+'