Add LWN.net CGI and 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 146e52c4312ce865597cbaaed0c3ab4d9d479985
(DIR) parent 54479ca33691d982674637d35a9176615eb21d5d
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Wed, 29 Aug 2018 11:52:38
Add LWN.net CGI and DCGI
Diffstat:
lwn/article.cgi | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lwn/feed.dcgi | 47 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 110 insertions(+), 0 deletions(-)
---
diff -r 54479ca33691 -r 146e52c4312c lwn/article.cgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwn/article.cgi Wed Aug 29 11:52:38 2018 +0200
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+
+#
+# Extract article content
+#
+extract_article()
+{
+
+ awk '
+ /<body/,/<\/body>/ {
+ print
+ }
+ '
+}
+
+
+#
+# Filter HTML content
+#
+filter_html()
+{
+
+ awk '
+ /<div class="PageHeadline">/,/<\/div>/ {
+ print
+ }
+
+ /<div class="ArticleText">/,/<\/div> <!-- ArticleText -->/ {
+ if ($0 !~ /Log in<\/a> to post comments\)/) {
+ print
+ }
+ }
+
+ '
+
+}
+
+
+#
+# Render HTML as text
+#
+html_to_text()
+{
+ # Nonexistent proxy to block HTTP requests
+ export http_proxy="http://localhost:31283128"
+
+ browser="/usr/pkg/bin/w3m"
+
+ browser_options="-dump -T text/html -no-cookie -cols 72"
+ browser_options="${browser_options} -o display_link=false"
+ browser_options="${browser_options} -o display_link_number=false"
+ browser_options="${browser_options} -o display_image=false"
+
+ env LANG=en_US.UTF-8 ${browser} ${browser_options}
+}
+
+
+url=$2
+/usr/pkg/bin/curl -sL "${url}" |
+ extract_article |
+ filter_html |
+ html_to_text
diff -r 54479ca33691 -r 146e52c4312c lwn/feed.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwn/feed.dcgi Wed Aug 29 11:52:38 2018 +0200
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+
+ARTICLE_CGI="/cgi/lwn/article.cgi"
+
+
+echo ""
+echo "LWN.net"
+echo ""
+
+url="https://lwn.net/headlines/newrss"
+/usr/pkg/bin/curl -gs "${url}" |
+awk '
+/<channel/,/<\/channel>/ {
+ next # ignore all non-item-s
+}
+
+/<title/ {
+ gsub("</?title>", "")
+ gsub(/^[[:space:]]+/, "")
+ gsub(/[[:space:]]+$/, "")
+ title = $0
+}
+
+/<link/ {
+ gsub("</?link>", "")
+ gsub(/^[[:space:]]+/, "")
+ gsub(/[[:space:]]+$/, "")
+ link = $0
+}
+
+title && link {
+ gsub("\\|", "\\|", title)
+ gsub("\\|", "\\|", link)
+
+ # XXX: Directly get the full story, not few lines of it.
+ gsub("/rss$", "/", link)
+
+ if (title !~ /^\[\$\] /) {
+ printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
+ }
+
+ title = link = ""
+}
+'
+
+echo ""