Add a CGI/DCGI for espresso.repubblica.it - 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 09cbd6d2abc3e6727ea6391b887a5906d8d31bbd
(DIR) parent 7f79d08fcdd0e6dd9e798c783d781432f698ded7
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Thu, 30 Aug 2018 00:58:04
Add a CGI/DCGI for espresso.repubblica.it
Diffstat:
espresso/article.cgi | 44 ++++++++++++++++++++++++++++++++++++++++++++
espresso/feed.dcgi | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)
---
diff -r 7f79d08fcdd0 -r 09cbd6d2abc3 espresso/article.cgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/espresso/article.cgi Thu Aug 30 00:58:04 2018 +0200
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+
+#
+# Extract article content
+#
+extract_article()
+{
+
+ awk '
+ /<article class="main-article/,/<\/article>/ {
+ if (($0 ~ /<aside class="tags-list">/) || ($0 ~ /<footer /)) {
+ exit
+ }
+
+ 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 |
+ html_to_text
diff -r 7f79d08fcdd0 -r 09cbd6d2abc3 espresso/feed.dcgi
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/espresso/feed.dcgi Thu Aug 30 00:58:04 2018 +0200
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+
+ARTICLE_CGI="/cgi/espresso/article.cgi"
+
+
+echo ""
+echo "l'Espresso"
+echo ""
+
+url="http://espresso.repubblica.it/rss?sezione=espresso"
+/usr/pkg/bin/curl -gs "${url}" |
+awk '
+/<rss/,/<lastBuildDate>/ {
+ 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)
+ gsub("\\"", "\"", title)
+
+ if (title !~ /^\[\$\] /) {
+ printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
+ }
+
+ title = link = ""
+}
+'
+
+echo ""