r.dcgi - 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
       ---
       r.dcgi
       ---
            1 #!/bin/sh
            2 
            3 . ../common/config.sh
            4 
            5 CGI="${CGI_BASEDIR}/reddit/r.dcgi"
            6 COMMENTS_CGI="${CGI_BASEDIR}/reddit/c.cgi"
            7 
            8 case "$2" in
            9 */*)
           10         subreddit="${2%%/*}"
           11         after="${2##*/}"
           12         url="https://www.reddit.com/r/${subreddit}/.json?after=${after}"
           13         ;;
           14 *)
           15         subreddit="${2}"
           16         url="https://www.reddit.com/r/${subreddit}/.json"
           17         ;;
           18 esac
           19 
           20 ua=""
           21 
           22 echo "t"
           23 echo "tr/${subreddit}"
           24 echo "t"
           25 
           26 curl -A "${ua}" -Lgs -- "${url}" |
           27 jq -r '
           28 ( .data.children[] | .data |
           29         "[h|\(.title | gsub("\\|"; "\\|") )|" +
           30             "URL:\(.url | gsub("\\|"; "\\|"))|server|port]",
           31         "t\(.author)   \( .created_utc | strftime("%F %H:%M") )",
           32         "tScore:    \(.score)",
           33         "[0|Comments: \(.num_comments)|" +
           34             "'"${COMMENTS_CGI}?${subreddit}/"'" + "\(.id)|server|port]",
           35         "t" ),
           36 ( if .data.after != "" then
           37         "[1|<< Previous page|" +
           38             "'"${CGI}?${subreddit}/"'" + "\(.data.after)|server|port]"
           39   else
           40         empty
           41   end
           42 )
           43 '