Add an edition CGI (extract articles based on a certain day) - 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 8921750c245138a30b4e41d79ac2ca05e6500c76 (DIR) parent 57112e2a27fe6d67a2a57db055467df4fa4de6e9 (HTM) Author: Leonardo Taccari <iamleot@gmail.com> Date: Sat, 8 Dec 2018 23:09:54 Add an edition CGI (extract articles based on a certain day) Diffstat: ilmanifesto/edition.dcgi | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) --- diff -r 57112e2a27fe -r 8921750c2451 ilmanifesto/edition.dcgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ilmanifesto/edition.dcgi Sat Dec 08 23:09:54 2018 +0100 @@ -0,0 +1,44 @@ +#!/bin/sh + +. ../common/config.sh + +ARTICLE_CGI="${CGI_BASEDIR}/ilmanifesto/article.cgi" + +edition="$2" + +echo "" +echo "il manifesto - ${edition}" +echo "" + +curl -A Googlebot-News -Lgs -- "https://ilmanifesto.it/edizione/il-manifesto-del-${edition}/" | +awk -v cgi="${ARTICLE_CGI}" ' +/<article class="edition-toc__item"/ { + # Extract all article information to generate the menu + n = split($0, a, /<\/article>/) + n -= 1 # Remove stray </div> + + for (i = 1; i <= n; i++) { + match(a[i], /href="[^"]+" title=/) + href = substr(a[i], RSTART + 6, RLENGTH - 14) + match(a[i], /title="[^"]+"/) + title = substr(a[i], RSTART + 7, RLENGTH - 8) + match(a[i], /<p class="autore">.*<\/p><p>/) + author = substr(a[i], RSTART + 18, RLENGTH - 25) + match(a[i], /<p>.*<\/p>$/) + description = substr(a[i], RSTART + 3, RLENGTH - 7) + + if (href && title) { + if (author) { + entry = title ", " author + } else { + entry = title + } + printf("[0|%s|%s?%s|server|port]\n", entry, cgi, href) + if (description) { + printf("t%s\n", description) + } + printf("\n") + } + } +} +'