Use common/feed.sh instead of (mostly) duplicate code - 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 11dfa97af3477693c43441e04e2a1c22bc893730
(DIR) parent 79f7a5a43f779011371b8bcaa3d0a5b484c4f1a1
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Fri, 7 Sep 2018 01:41:28
Use common/feed.sh instead of (mostly) duplicate code
Diffstat:
acmqueue/feed.dcgi | 32 +-----------------------
ansa/feed.dcgi | 34 +-------------------------
espresso/feed.dcgi | 34 +-------------------------
lwn/feed.dcgi | 58 ++++++++++++++++++---------------------------
technologyreview/feed.dcgi | 30 +----------------------
theatlantic/feed.dcgi | 34 +-------------------------
theguardian/feed.dcgi | 31 +-----------------------
7 files changed, 35 insertions(+), 218 deletions(-)
---
diff -r 79f7a5a43f77 -r 11dfa97af347 acmqueue/feed.dcgi
--- a/acmqueue/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/acmqueue/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,41 +1,13 @@
#!/bin/sh
+. ../common/feed.sh
ARTICLE_CGI="/cgi/acmqueue/article.cgi"
-
echo ""
echo "ACM Queue"
echo ""
url="https://queue.acm.org/rss/feeds/queuecontent.xml"
/usr/pkg/bin/curl -gs "${url}" |
-awk '
-/<rss/,/<item/ {
- 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("&", "\\&", link)
-
- printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
-
- title = link = ""
-}
-'
+feed_to_gph
diff -r 79f7a5a43f77 -r 11dfa97af347 ansa/feed.dcgi
--- a/ansa/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/ansa/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,43 +1,13 @@
#!/bin/sh
+. ../common/feed.sh
ARTICLE_CGI="/cgi/ansa/article.cgi"
-
echo ""
echo "ANSA"
echo ""
url="http://www.ansa.it/sito/ansait_rss.xml"
/usr/pkg/bin/curl -gs "${url}" |
-{ /usr/pkg/bin/xmllint --format - 2>/dev/null ; } |
-awk '
-/<channel>/,/<copyright>/ {
- 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("^<!\\[CDATA\\[ *", "", title)
- gsub(" *\\]\\]>$", "", title)
-
- printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
-
- title = link = ""
-}
-'
+feed_to_gph
diff -r 79f7a5a43f77 -r 11dfa97af347 espresso/feed.dcgi
--- a/espresso/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/espresso/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,43 +1,13 @@
#!/bin/sh
+. ../common/feed.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 = ""
-}
-'
+feed_to_gph
diff -r 79f7a5a43f77 -r 11dfa97af347 lwn/feed.dcgi
--- a/lwn/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/lwn/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,46 +1,34 @@
#!/bin/sh
+. ../common/feed.sh
+
+filter_entries()
+{
+
+ awk '
+ /^\[0\|\[\$\]/ {
+ # ignore all non-free articles
+ next
+ }
+ /\/rss\|server\|port\]$/ {
+ # Get rid of "/rss" in link in order to get the full story
+ # (not few lines of it!)
+ sub(/\/rss/, "/")
+ }
+
+ {
+ print
+ }
+'
+}
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:]]+$/, "")
- gsub(/"/, "\"")
- 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 = ""
-}
-'
+feed_to_gph |
+filter_entries
diff -r 79f7a5a43f77 -r 11dfa97af347 technologyreview/feed.dcgi
--- a/technologyreview/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/technologyreview/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,5 +1,6 @@
#!/bin/sh
+. ../common/feed.sh
ARTICLE_CGI="/cgi/technologyreview/article.cgi"
@@ -9,31 +10,4 @@
url="https://www.technologyreview.com/stories.rss"
/usr/pkg/bin/curl -gs "${url}" |
-awk '
-/<rss/,/<item/ {
- 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)
-
- printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
-
- title = link = ""
-}
-'
+feed_to_gph
diff -r 79f7a5a43f77 -r 11dfa97af347 theatlantic/feed.dcgi
--- a/theatlantic/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/theatlantic/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,9 +1,9 @@
#!/bin/sh
+. ../common/feed.sh
ARTICLE_CGI="/cgi/theatlantic/article.cgi"
-
section="$2"
case "${section}" in
politics|business|entertainment|international|technology|national|health| \
@@ -22,34 +22,4 @@
url="https://www.theatlantic.com/feed/channel/${section}/"
/usr/pkg/bin/curl -gs "${url}" |
-{ /usr/pkg/bin/xmllint --format - 2>/dev/null ; } |
-awk '
-/<feed/,/<rights>/ {
- next # ignore all non-entry-s
-}
-
-/<title/ {
- gsub("<title type=\"html\">", "")
- gsub("</title>", "")
- gsub(/^[[:space:]]+/, "")
- gsub(/[[:space:]]+$/, "")
- title = $0
-}
-
-/<link/ {
- gsub("<link href=\"", "")
- gsub("\" rel=\"alternate\"/>", "")
- gsub(/^[[:space:]]+/, "")
- gsub(/[[:space:]]+$/, "")
- link = $0
-}
-
-title && link {
- gsub("\\|", "\\|", title)
- gsub("\\|", "\\|", link)
-
- printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
-
- title = link = ""
-}
-'
+feed_to_gph
diff -r 79f7a5a43f77 -r 11dfa97af347 theguardian/feed.dcgi
--- a/theguardian/feed.dcgi Fri Sep 07 01:32:27 2018 +0200
+++ b/theguardian/feed.dcgi Fri Sep 07 01:41:28 2018 +0200
@@ -1,9 +1,9 @@
#!/bin/sh
+. ../common/feed.sh
ARTICLE_CGI="/cgi/theguardian/article.cgi"
-
section="$2"
#
# TODO: Should we try to validate section?
@@ -15,31 +15,4 @@
url="https://www.theguardian.com/${section}/rss"
/usr/pkg/bin/curl -gs "${url}" |
-awk '
-/<rss/,/<item/ {
- 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)
-
- printf("[0|%s|'"${ARTICLE_CGI}?"'%s|server|port]\n", title, link)
-
- title = link = ""
-}
-'
+feed_to_gph