SHARE
TWEET

psCheckComments.sh

Eardwulf Mar 1st, 2015 (edited) 261 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # v.0.3b - usage: ./psCheckComments.sh URL
  3. # or modify var $url
  4. # rm {HOME}/.ps-* # to remove old compare files
  5. # changes: can now handle more urls, some bugfixes
  6.  
  7. url="${1}"
  8. [ -z "${url}" ] && url=https://propagandamelder.wordpress.com/2015/03/11/propagandameldungen-vom-11-marz-2015/
  9.  
  10. bname=`echo "${url}" | md5sum | awk '{print "ps-"$1}'`
  11.  
  12. tmpf="${HOME}/.${bname}.tmp"
  13. difftmpf="${HOME}/.${bname}.difftmp"
  14. compf="${HOME}/.${bname}.completePage"
  15. cmpf="${HOME}/.${bname}.compare"
  16.  
  17. lynx -dump  ${url} | tee ${compf} | sed -n -e '/Gedanke[n ] zu/,/Kommentar verfassen/p' | tee ${tmpf} | sed 's/\[[0-9]*\]//g' > ${difftmpf}
  18.  
  19. [ ! -f ${cmpf} ] && touch ${cmpf}
  20.  
  21. linkingPrinting() {
  22.  oIFS=${IFS}
  23.  IFS="@#@"
  24.  for s in ${1}; do
  25.   if [ ! -z "${s}" ]; then
  26.    IFS=${oIFS}
  27.     for num in `grep -n "${s}" ${difftmpf} | awk -F: '{print $1}'`; do
  28.      linknumber=`cat ${tmpf} | head -${num} | tail -1 | awk -F \] '{print $1}' | sed 's/\[//g' | sed 's/\s//g'`
  29.      echo "--------------------------------------------------------------------------"
  30.      echo "Link: `cat ${compf} | grep -w "${linknumber}" | grep "${linknumber}. http"`"
  31.      echo "--------------------------------------------------------------------------"
  32.      from=${num}
  33.      to=`cat ${difftmpf} | sed  -n -e ${from},"/sagte:/p" | grep -n "sagte:" | awk -F: '{print $1}'`
  34.      if [ -z "${to}" ]; then  # last entry fix
  35.       to=`cat ${difftmpf} | sed  -n -e ${from},"/Kommentar verfassen/p"  | grep -n "Kommentar verfassen" | awk -F: '{print $1}'`
  36.      fi
  37.      to=`expr $from + $to - 2`
  38.      from=`expr ${num} - 1`
  39.      cat ${difftmpf} | sed 's/\"/\\\"/g' | sed -n -e ${from},${to}p | grep -v "llt mir" | grep -vw "Antwort"
  40.     done
  41.    IFS="@#@"
  42.   fi
  43.  done
  44.  IFS=${oIFS}
  45. }
  46.  
  47. diffmdtmpf=`md5sum ${difftmpf} | awk '{print $1}'`
  48. mdcmpf=`md5sum ${cmpf} | awk '{print $1}'`
  49.  
  50. difftmpfCmntCount=`cat ${difftmpf} | head -1 | awk '{print $1}'`
  51. cmpfCmntCount=`cat ${cmpf} | head -1 | awk '{print $1}'`
  52. [ -z "${cmpfCmntCount}" ] && cmpfCmntCount=0
  53.  
  54. echo "+++++++++++++++++++++ `date` ++++++++++++++++++++++++++"
  55. echo "current comments on ${url}: ${difftmpfCmntCount}"
  56.  
  57. if [ "${diffmdtmpf}" != "${mdcmpf}" ]; then
  58.  echo "`expr ${difftmpfCmntCount} - ${cmpfCmntCount}` new comment(s)! - linking/ printing:"
  59.  linkingPrinting "`sdiff ${difftmpf} ${cmpf} | grep "[<]" | sed 's/<$//g' | grep "um [0-9]*:[0-9]*" | sed 's/^[ \t]*//;s/[ \t]*$//' | awk '{print $0"@#@"}' | sort -n |sort -u | tr -d '\n'`"
  60.  mv ${difftmpf} ${cmpf}
  61. else
  62.   echo "no new comments :/"
  63. fi
  64.  
  65. echo "--------------------------------------------------------------------------"
  66.  
  67. [ -f ${tmpf} ] && rm ${tmpf}
  68. [ -f ${difftmpf} ] && rm ${difftmpf}
  69. [ -f ${compf} ] && rm ${compf}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top