Introduce a fetch() function to avoid duplicate code in timeline()/status() - 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 c52fbed7c809d27e07f21a872cabb8a69c2298dc
 (DIR) parent c1665e58af51f8a9452e323467289d4ac8bfaf23
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Mon, 17 Dec 2018 13:14:35 
       
       Introduce a fetch() function to avoid duplicate code in timeline()/status()
       
       NFCI, except that also for timeline() now a not needed "<li>" is
       added, but this is harmless and avoid code duplication (it is needed
       for status()!).
       
       Diffstat:
        twitter/tweets.dcgi |  33 ++++++++++++++++++---------------
        1 files changed, 18 insertions(+), 15 deletions(-)
       ---
       diff -r c1665e58af51 -r c52fbed7c809 twitter/tweets.dcgi
       --- a/twitter/tweets.dcgi       Mon Dec 17 13:04:40 2018 +0100
       +++ b/twitter/tweets.dcgi       Mon Dec 17 13:14:35 2018 +0100
       @@ -38,6 +38,22 @@
        
        
        #
       +# Fetch twitter URL and tscrape it.
       +#
       +fetch()
       +{
       +       url=$1
       +
       +       {
       +               echo "<div class=\"user-actions\"";
       +               echo "     data-screen-name=\"${username}\"";
       +               echo "     data-name=\"${name}\">";
       +               echo "<li class=\"js-stream-item\">";
       +               curl -Lgs -- "${url}" | jq -r '.items_html';
       +       } | tscrape
       +}
       +
       +#
        # Given a username and optional max id tscrape the next 20 tweets
        #
        timeline()
       @@ -50,13 +66,7 @@
               if [ "${maxid}" ]; then
                       url="${url}&max_position=${maxid}"
               fi
       -
       -       {
       -               echo "<div class=\"user-actions\"";
       -               echo "     data-screen-name=\"${username}\"";
       -               echo "     data-name=\"${name}\">";
       -               curl -Lgs -- "${url}" | jq -r '.items_html';
       -       } | tscrape
       +       fetch "${url}"
        }
        
        
       @@ -70,14 +80,7 @@
               id=$2
        
               url="${base}/${username}/status/${id}"
       -
       -       {
       -               echo "<div class=\"user-actions\"";
       -               echo "     data-screen-name=\"${username}\"";
       -               echo "     data-name=\"${name}\">";
       -               echo "<li class=\"js-stream-item\">";
       -               curl -Lgs -- "${url}" ;
       -       } | tscrape
       +       fetch "${url}"
        }