Add initial mastodon 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
---
(DIR) changeset cb6b16c1ac5ac018ff8acfe8505ade3fff0e02b6
(DIR) parent 855b00269042fd152d2088d35b10c1b95b9a738b
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Mon, 17 Dec 2018 00:00:48
Add initial mastodon DCGI
Diffstat:
mastodon/mastodon.dcgi | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 84 insertions(+), 0 deletions(-)
---
diff -r 855b00269042 -r cb6b16c1ac5a mastodon/mastodon.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mastodon/mastodon.dcgi Mon Dec 17 00:00:48 2018 +0100
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+. ../common/config.sh
+
+CGI="${CGI_BASEDIR}/mastodon/mastodon.dcgi"
+
+
+url=$2
+
+
+#
+# Parse all mastodon toots and format them to gph
+#
+mastodon_gph()
+{
+
+ awk -v cgi="${CGI}" \
+'
+ function print_tootcontent(c)
+ {
+ cmd = "http_proxy=\"http://localhost:31283128\""
+ cmd = cmd " LANG=en_US.UTF-8"
+ cmd = cmd " w3m -T text/html"
+ cmd = cmd " -dump -no-cookie -cols 72"
+ cmd = cmd " -o display_link=false"
+ cmd = cmd " -o display_link_number=false"
+ cmd = cmd " -o display_image=false"
+ cmd = cmd " -o pseudo_inlines=false"
+ cmd = cmd " | sed -e \"s/^/t/\""
+
+ print c | cmd
+ close(cmd)
+ }
+
+ function print_toot(t)
+ {
+ desc = sprintf("%s @%s %s",
+ t["fullname"], t["username"], t["time"])
+ gsub("\\|", "\\|", desc)
+
+ printf("[1|%s|%s?%s|server|port]\n", desc, cgi, t["url"])
+ print_tootcontent(t["content"])
+ }
+
+ {
+ if (match($0, /class="status__relative-time/)) {
+ match($0, />[^<]+<\/time>$/)
+ toot["time"] = substr($0, RSTART + 1, RLENGTH - 8)
+ match($0, /href="[^"]+"/)
+ toot["url"] = substr($0, RSTART + 6, RLENGTH - 7)
+ }
+
+ if (match($0, /class="status__display-name/)) {
+ match($0, /@[^"]+/)
+ toot["username"] = substr($0, RSTART + 1, RLENGTH - 1)
+ }
+
+ if (match($0, /class=.display-name__html/)) {
+ match($0, /.>[^<]+</)
+ toot["fullname"] = substr($0, RSTART + 2, RLENGTH - 3)
+ }
+
+ if (match($0, /class=.status__content/)) {
+ gsub(/'/, "\\'");
+ toot["content"] = $0
+ }
+
+ if (toot["content"]) {
+ print_toot(toot)
+
+ toot["time"] = ""
+ toot["url"] = ""
+ toot["username"] = ""
+ toot["fullname"] = ""
+ toot["content"] = ""
+ }
+ }
+'
+}
+
+echo ""
+echo "Mastodon"
+echo ""
+curl -Lgs -- "${url}" | mastodon_gph