edition.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
       ---
       edition.dcgi
       ---
            1 #!/bin/sh
            2 
            3 . ../common/config.sh
            4 
            5 ARTICLE_CGI="${CGI_BASEDIR}/ilmanifesto/article.cgi"
            6 
            7 edition="$2"
            8 
            9 echo ""
           10 echo "il manifesto - ${edition}"
           11 echo ""
           12 
           13 curl -A Googlebot-News -Lgs -- "https://ilmanifesto.it/edizione/il-manifesto-del-${edition}/" |
           14 awk -v cgi="${ARTICLE_CGI}" '
           15 function decode(s)
           16 {
           17         gsub(/’/, "\047", s);
           18         gsub(/“/, "\042", s);
           19         gsub(/”/, "\042", s);
           20 
           21         gsub("\\|", "\\|", s)
           22 
           23         return s
           24 }
           25 
           26 function print_description(text)
           27 {
           28         cmd = "par -d 0 -B=. -w 72"
           29         cmd = cmd " | sed -e \"s/^/t/\""
           30 
           31         print text | cmd
           32         close(cmd)
           33 }
           34 
           35 /<article class="edition-toc__item"/ {
           36         # Extract all article information to generate the menu
           37         n = split($0, a, /<\/article>/)
           38         n -= 1  # Remove stray </div>
           39 
           40         for (i = 1; i <= n; i++) {
           41                 match(a[i], /href="[^"]+" title=/)
           42                 href = substr(a[i], RSTART + 6, RLENGTH - 14)
           43                 match(a[i], /title="[^"]+"/)
           44                 title = substr(a[i], RSTART + 7, RLENGTH - 8)
           45                 match(a[i], /<p class="autore">.*<\/p><p>/)
           46                 author = substr(a[i], RSTART + 18, RLENGTH - 25)
           47                 match(a[i], /<p>.*<\/p>$/)
           48                 description = substr(a[i], RSTART + 3, RLENGTH - 7)
           49 
           50                 title = decode(title)
           51                 author = decode(author)
           52                 description = decode(description)
           53 
           54                 if (href && title) {
           55                         if (author) {
           56                                 entry = title ",   " author
           57                         } else {
           58                                 entry = title
           59                         }
           60                         printf("[0|%s|%s?%s|server|port]\n", entry, cgi, href)
           61                         if (description) {
           62                                 print_description(description)
           63                         }
           64                         printf("\n")
           65                 }
           66         }
           67 }
           68 '