Advertisement
uriel1998

BASH script to read Remember The Milk's RSS feed

Oct 1st, 2011
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. tmpfile=$(mktemp)
  4.  
  5. RSS_URL=https://USERNAME:PASSWORD@www.rememberthemilk.com/rss/USERNAME/;
  6. wget ${RSS_URL} -O - 2>/dev/null | xmlstarlet sel -T -t -m "/rss/channel/item" -o "|" -v "title" -o "|" -v "link" -o "|" -v "description" -o "|" -n |sed '/^$/d' | sed '/^|/!d' | sed '/|$/!s/^.*$/&<\/div><\/div><\/div><\/div>|/g' > $tmpfile
  7.  
  8. # There's a problem with the description - newlines muck it up.  Unfortunately, the date is in the description.  Oy.  
  9. # Hence all that mucking about with SED.
  10. # SED order - get rid of extra newlines, get rid of those that don't start with a | marker, add closing </div> tags and | to truncated lines.
  11. # This is not ideal, because it means we don't get notes and the like.  But this kludge here has taken me long enough.
  12. # By the way, the problem is that the notes (and indeed, the whole description) is NOT XML.  It's done with HTML spans.
  13.  
  14. i=0  
  15. cat $tmpfile |  while read line; do  
  16.     let i++
  17.     TASKTitle[$i]=$(echo $line|awk '{split($0,a,"|");print a[2]}')
  18.     # Currently this array field is just a storage space, but it could be used later when I figure out how to parse the notes better.
  19.     TASKDescription[$i]=$(echo $line|awk '{split($0,a,"|");print a[4]}')
  20.     TASKLink[$i]=$(echo $line|awk '{split($0,a,"|");print a[3]}')
  21.         TASKDate[$i]=$(echo ${TASKDescription[$i]}| awk -F'[<|>]' '/rtm_due_value/{print $11}')
  22.     #Currently outputs to the console.
  23.     echo ${TASKTitle[$i]} "," ${TASKDate[$i]} "," ${TASKLink[$i]}  
  24. done
  25.  
  26. # Put here a function to search for things today.
  27. # Put here a function to search for things on any given date.
  28. # Put here a function to search for things with no date.
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement