Add a duckduckgo search 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
       ---
 (DIR) changeset 0756b7b83216179ba4c0f09c6300a9c3512f04d0
 (DIR) parent 3a6aad2e82fffb8f05dfb3dec7fc55faf4a40425
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Wed, 27 Feb 2019 11:05:37 
       
       Add a duckduckgo search DCGI
       
       Still very experimental and limited (pagination not supported ATM).
       
       Diffstat:
        duckduckgo/search.dcgi |  54 ++++++++++++++++++++++++++++++++++++++++++++++++++
        1 files changed, 54 insertions(+), 0 deletions(-)
       ---
       diff -r 3a6aad2e82ff -r 0756b7b83216 duckduckgo/search.dcgi
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/duckduckgo/search.dcgi    Wed Feb 27 11:05:37 2019 +0100
       @@ -0,0 +1,54 @@
       +#!/bin/sh
       +
       +. ../common/config.sh
       +
       +SEARCH_CGI="${CGI_BASEDIR}/duckduckgo/search.dcgi"
       +
       +if [ -n "$1" ]; then
       +       query=$1
       +       url="https://duckduckgo.com/lite"
       +else
       +       exit 1
       +fi
       +
       +echo "t"
       +echo "tDuckDuckGo"
       +echo "t"
       +
       +curl -A '' -Lgs -d "q=${query}" -- "${url}" |
       +awk \
       +'
       +function gphize(s)
       +{
       +       gsub("\\|", "\\|", s)
       +       return s
       +}
       +
       +function html_decode(s)
       +{
       +       gsub(/&quot;/, "\"", s);
       +       gsub(/&amp;/, "\\&", s);
       +       return s
       +}
       +
       +function html_to_text(s)
       +{
       +       gsub(/<[^>]+>/, "", s)
       +       return html_decode(s)
       +}
       +
       +/class=.result-link./ {
       +       if (match($0, /href="[^"]+"/)) {
       +               url = substr($0, RSTART + 6, RLENGTH - 7)
       +       }
       +
       +       if (match($0, /class=.result-link.>.*<\/a>$/)) {
       +               title = substr($0, RSTART + 20, RLENGTH - 24)
       +               title = html_to_text(title)
       +       }
       +
       +       if (url && title) {
       +               printf("[h|%s|URL:%s|host|port]\n", gphize(title), url)
       +       }
       +}
       +'