procmail
[Top] [All Lists]

Re: procmail/sed script for Travelocity fare updates

2001-03-05 05:35:58
On  2 Mar, Timothy J. Luoma wrote:
| 
| I think I've successfully written a procmail/sed script which will take a Fare
| Watcher update (from Travelocity.com) and forward just the important part to a
| pager.
| 
| [...]
| 
| Here is the script
| 
| :0c
| {
|       :0fbw
|       * ^From:(_dot_)*memberservices(_at_)travelocity\(_dot_)com
|       * ^Subject: Travelocity.com fare watcher update
|       | fgrep -A2 -B2 "PRICE:"  |\
|               egrep -vi "PRICE:|----" |\
|               sed 's/.00 /.00\n/g' |\
|               sed '$d' |\
|               tr -s '\012' ' ' |\
|               tr -s ' ' |\
|               sed 's/.*FROM: /From /g; s/ TO: / to /g; s/(...) //g; s/.00 \$/ 
was \$/g'
| 
|       :0
|       ! email(_at_)pagercompany(_dot_)com
| }
| 
| 
| Here's an example of the email that I receive
| 
| Date: Fri, 2 Mar 2001 06:06:48 -0600 (CST)
| From: Fare Watcher <memberservices(_at_)travelocity(_dot_)com>
| Subject: Travelocity.com fare watcher update
| 
| [...]
| 
| http://dps1.travelocity.com:80/fwemindiv.ctl?fw=99102906758166|TRAVELOCITY
| 
| =======   FARES     ============================
| 
| *  JAX-GLA   FROM: JACKSONVILLE, FL (JAX)
|              TO:   GLASGOW, UK (GLA)
|    PRICE:    NEW PRICE      WAS      DIFFERENCE
|              ---------    -------    ----------
|              $575.00      $678.00     -$103.00
| 
| 
| 

David Tamkin has already suggested some improvements to the sed code,
but I was playing with this and figured I'd pass it on. I don't know if
you copied and pasted something wrong or if I did, but I can't make your
pipeline work (at a shell prompt) the way it's apparently intended. I
only get the travel points without prices. I don't know if this is
better (more efficient), but it's just one process:

  :0fbw
  * ^From:(_dot_)*memberservices(_at_)travelocity\(_dot_)com
  * ^Subject: Travelocity.com fare watcher update
  |perl -ne 'print(/(?:FROM|TO):\s*([^(]+)/g);\
  /(\$[\d.,]+).*(-\$[\d.,]+)/ and print "$1 $2\n";'


Note, for some unknown reason I actually did test this and it works, but
only if the perl one-liner is on one line. The line break above is for
readability only. In fact, depending on where I put line breaks (while
playing with this and others) the pipe would either fail or just not
work correctly. If anyone has an explanation for that, maybe this could
be remotely on topic.

The recipe above will also collect more than one fare update in the same
message, where yours I believe would only pass the last one. Of course
that's meaningless if there's never more than one. The output is more
sparse than yours, and reports fare difference rather than old price,
but otherwise has the pertinent information. (It also assumes only
price decreases are reported.)  It's pretty trivial to spruce up the
output, but I figured this might be good enough to a pager.

Note I didn't keep the cc: to sed-users list because there's no need to
start a sed/perl flamefest on the procmail list. ;-)

-- 
 /"\                                                 Don Hammond
 \ /     ASCII RIBBON CAMPAIGN
  X        AGAINST HTML MAIL,
 / \      AND NEWS TOO

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail