Advertisement
pasto

LPnewswire_00_blog

Oct 7th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. # LPnewswire draft, Albert Schaferle 2014-10-04
  2. feedURI="http://feeds.reuters.com/Reuters/worldNews"
  3. TMPt0=/tmp/LPnewswire.t0
  4. TMPt1=/tmp/LPnewswire.t1
  5. TMPdelta=/tmp/LPnewswire.delta
  6. NLOG=~/LPnewswire/lpnlog
  7. touch $TMPt0
  8. curl --silent $feedURI | xml2 > $TMPt1
  9. feedNAME=$(cat $TMPt1 | grep "^/rss/channel/title" | cut -d\= -f2)
  10. echo -n "Started reading from "$feedNAME" on " | tee -a $NLOG
  11. date -R | tee -a $NLOG
  12. echo "Priting new headlines from "$feedNAME" - press CTRL + C to exit"
  13. while true
  14. do
  15.     curl --silent $feedURI | xml2 > $TMPt1
  16.     diff --ignore-blank-lines -b --ignore-case --old-line-format='' \
  17.          --new-line-format='%L' --unchanged-line-format='' \
  18.            $TMPt0 $TMPt1 > $TMPdelta
  19.         if [[ -s $TMPdelta ]] ; then # is delta non-empty?
  20.         NTIME=$(date -R)
  21.         NNEWL=$(cat $TMPdelta | wc -l)
  22.         echo "Found "$NNEWL" new lines @ "$NTIME | tee -a $NLOG
  23.         cat $TMPdelta | # bold title, normal description, rh-justified pubDate, all NLQ
  24.             grep "^/rss/channel/item/title\|^/rss/channel/item/description\|^/rss/channel/item/pubDate" |
  25.             sed '/title=/ s/$/ \\e\\x46/' |
  26.             sed 's,/rss/channel/item/title=,\\e\\x78\\x01\\e\\x61\\x00\\e\\x45\\e\\x47\n,' |
  27.             sed 's,/rss/channel/item/description=,,' |
  28.             sed 's,/rss/channel/item/pubDate=,\\e\\x46\\e\\x61\\x02,' |
  29.             cut -d\< -f1 |
  30.             sed '/^$/d' |
  31.             iconv -f UTF-8 -t IBM437 |
  32.             xargs --null echo -ne |
  33.             fold -sw 80 |
  34.             lpr -P lpt-raw
  35.         cp $TMPt1 $TMPt0 # I'm copying to cover up against curl giving blank output
  36.         else echo "."
  37.     fi ;
  38. sleep 1m
  39. done
  40. echo "LPnewswire on "$feedNAME" exiting."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement