|
Revision 1434, 1.4 kB
(checked in by jm3, 1 year ago)
|
initial commit
|
- Property svn:executable set to
*
|
| Line | |
|---|
| 1 |
#!/bin/sh |
|---|
| 2 |
# jm3 / john manoogian III / jm3.net |
|---|
| 3 |
# hacky hack hack |
|---|
| 4 |
|
|---|
| 5 |
export PATH=/usr/local/bin:/bin:/usr/bin |
|---|
| 6 |
|
|---|
| 7 |
restaurant=$1 |
|---|
| 8 |
if [ -z "$restaurant" ] |
|---|
| 9 |
then |
|---|
| 10 |
echo "usage: $0 'restaurant name'" |
|---|
| 11 |
exit 1 |
|---|
| 12 |
fi |
|---|
| 13 |
|
|---|
| 14 |
# load any server-specific vars: |
|---|
| 15 |
. env.sh |
|---|
| 16 |
|
|---|
| 17 |
restaurant=`echo "$restaurant" | tr '[A-Z]' '[a-z]' | sed "s/ /+/g" | sed "s/[^a-z0-9%_\+\.'-]//g" | sed "s/'/%27/g"` |
|---|
| 18 |
token=`echo "$restaurant" | sed "s/[+']/-/g"` |
|---|
| 19 |
cache_file=$env_root/cache/$token.cache |
|---|
| 20 |
url="http://www.yelp.com/search?find_desc=$restaurant&find_loc=San+Francisco" |
|---|
| 21 |
|
|---|
| 22 |
# check for previous cachefile |
|---|
| 23 |
if [ -f $cache_file ] |
|---|
| 24 |
then |
|---|
| 25 |
today=`date "+%G-%m-%d"` |
|---|
| 26 |
cache_date=`stat -c "%y" $cache_file | sed "s/ .*$//"` |
|---|
| 27 |
if [ "$cache_date" = "$today" ] |
|---|
| 28 |
then |
|---|
| 29 |
cat $cache_file |
|---|
| 30 |
exit 0 |
|---|
| 31 |
else |
|---|
| 32 |
echo "|$cache_date|" |
|---|
| 33 |
echo "|$today|" |
|---|
| 34 |
fi |
|---|
| 35 |
fi |
|---|
| 36 |
|
|---|
| 37 |
TMPFILE=`mktemp $env_root/cache/tmp.XXXXXXXXXX` |
|---|
| 38 |
|
|---|
| 39 |
echo "<html>" > $TMPFILE |
|---|
| 40 |
curl "$url" \ |
|---|
| 41 |
| tidy -n -q -asxml \ |
|---|
| 42 |
| sed 's/<html xmlns="http:\/\/www.w3.org\/1999\/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">//' \ |
|---|
| 43 |
| grep -v xhtml1-transitional.dtd \ |
|---|
| 44 |
| grep -v '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v=' \ |
|---|
| 45 |
| grep -v '"urn:schemas-microsoft-com:vml">' \ |
|---|
| 46 |
| grep -v "DOCTYPE html PUBLIC" > $cache_file |
|---|
| 47 |
cat $cache_file >> $TMPFILE |
|---|
| 48 |
mv $TMPFILE $cache_file |
|---|
| 49 |
xsltproc --novalid extract-rating.xsl $cache_file > $TMPFILE |
|---|
| 50 |
mv $TMPFILE $cache_file |
|---|
| 51 |
chmod a+w $cache_file |
|---|
| 52 |
cat $cache_file |
|---|
| 53 |
exit 0 |
|---|
| 54 |
|
|---|