rep.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
       ---
       rep.dcgi
       ---
            1 #!/bin/sh
            2 
            3 . ../common/config.sh
            4 
            5 ARTICLE_CGI="${CGI_BASEDIR}/rep/article.cgi"
            6 
            7 #
            8 # If an argument is provided use that as search criteria, otherwise just fetch
            9 # and parse the cover.
           10 #
           11 if [ -n "$2" ]; then
           12         search="$2"
           13         url="https://rep.repubblica.it/ws/search?${search}"
           14 else
           15         url="https://rep.repubblica.it/ws/cover.json"
           16 fi
           17 
           18 echo ""
           19 echo "Rep - Repubblica"
           20 echo ""
           21 
           22 curl -Lgs -- "${url}" |
           23 jq -r '.feed.zones | .[].blocks | .[].entries | .[] |
           24         .title + "\u001c" +
           25         .author + "\u001c" +
           26         .created[0:10] + "\u001c" +
           27         .links[1].href + "\u001c" +
           28         .summary + "\u001e"
           29 ' | awk '
           30 
           31 BEGIN {
           32         FS = "\034"
           33         RS = "\036"
           34 }
           35 
           36 function html_decode(s)
           37 {
           38         gsub(/“/, "\"", s);
           39         gsub(/”/, "\"", s);
           40         gsub(/’/, "\047", s);
           41         gsub(/"/, "\"", s);
           42         gsub(/à/, "à", s);
           43         gsub(/é/, "é", s);
           44         gsub(/è/, "è", s);
           45         gsub(/ì/, "ì", s);
           46         gsub(/ò/, "ò", s);
           47         gsub(/ù/, "ù", s);
           48 
           49         return s
           50 }
           51 
           52 NF == 5 {
           53         gsub(/\n/, "")
           54 
           55         title = $1
           56         author = $2
           57         created = $3
           58         link = $4
           59         summary = $5
           60 
           61         gsub("\\|", "\\|", title)
           62         gsub("\\|", "\\|", link)
           63 
           64         title = html_decode(title)
           65         desc = title
           66         if (author) {
           67                 desc = desc " " author
           68         }
           69         if (created) {
           70                 desc = desc " (" created ")"
           71         }
           72 
           73         printf("[0|%s|%s|server|port]\n", desc, "'${ARTICLE_CGI}?'" link)
           74 }
           75 '