1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
#export http_proxy=http://proxy.pliva.hr:8080 |
export http_proxy=http://proxy:8080 |
4 |
|
|
5 |
#isbn="0-201-41975-0" |
if [ -z "$1" ] ; then |
6 |
isbn="0-672-32240-4" |
echo "Usage: $0 ISBN" |
7 |
|
exit 1 |
8 |
|
fi |
9 |
|
|
10 |
|
isbn=$1; |
11 |
|
|
12 |
wait=10 |
wait=10 |
13 |
|
|
25 |
} |
} |
26 |
|
|
27 |
function geturl() { |
function geturl() { |
28 |
hindent -s $1 | grep $2 | grep -i href | grep mode=[st][eo]c | \ |
hindent -s $1 | grep -i href | grep mode=[st][eo]c | \ |
29 |
sed -e 's/^.*<a.*href="//i' \ |
sed -e 's/^.*<a.*href="//i' \ |
30 |
-e 's/".*//' -e 's/amp;//g' \ |
-e 's/".*//' -e 's/amp;//g' \ |
31 |
-e 's,^[^\?]*\?,http://safari.oreilly.com/,' \ |
-e 's,^[^\?]*\?,http://safari.oreilly.com/,' \ |
32 |
-e 's/#$//' \ |
-e 's/#$//' \ |
33 |
-e 's/srchText=//' | \ |
-e 's/\&srchText=//' \ |
34 |
grep -v open=false | \ |
-e 's/open=false/open=true/' | \ |
|
grep -v 'view=[A-Z].*%2F[^i]' | \ |
|
|
grep -v 'view=[A-Z].*/[^i]' | \ |
|
35 |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
36 |
|
grep $2 | \ |
37 |
sort -u >> in |
sort -u >> in |
38 |
} |
} |
39 |
|
|
40 |
echo > in |
function uniqurl() { |
41 |
#mirror "http://safari.oreilly.com/?XmlId=$isbn" |
mv in in.tmp |
42 |
|
grep -v 'view=[A-Z]' in.tmp | sort -u > in |
43 |
|
grep 'view=[A-Z].*/index' in.tmp | sort -u >> in |
44 |
|
} |
45 |
|
|
46 |
|
function mirror_in() { |
47 |
|
cat in | while read url ; do |
48 |
|
mirror "$url" |
49 |
|
|
50 |
|
if grep 'promo.asp' `ls -t index.html* | head -3` >/dev/null ; then |
51 |
|
echo "WARNING: safari seems to logunt you as user. Aborting." |
52 |
|
exit 1 |
53 |
|
fi |
54 |
|
done |
55 |
|
} |
56 |
|
|
57 |
|
echo -n > in |
58 |
|
mirror "http://safari.oreilly.com/?XmlId=$isbn" |
59 |
|
|
60 |
echo "extract URLs from first page..." |
echo "extract URLs from first page..." |
61 |
geturl "index.html?XmlId=$isbn" $isbn |
geturl "index.html?XmlId=$isbn" $isbn |
62 |
|
uniqurl |
63 |
|
|
64 |
mirror "-i in" |
mirror_in |
65 |
|
|
66 |
echo -n "extracting URLs [1]" |
echo -n "extracting URLs [1]" |
67 |
ls index.html* | while read file ; do |
ls index.html* | while read file ; do |
70 |
done |
done |
71 |
echo |
echo |
72 |
|
|
73 |
sort -u in > in2 |
uniqurl |
74 |
|
|
75 |
mirror "-i in2" |
mirror_in |
76 |
|
|
77 |
echo > in |
echo -n > in |
78 |
echo -n "extracting URLs [2]" |
echo -n "extracting URLs [2]" |
79 |
ls index.html* | while read file ; do |
ls index.html* | while read file ; do |
80 |
echo -n "." |
echo -n "." |
81 |
geturl $file $isbn |
geturl $file $isbn |
82 |
done |
done |
83 |
|
|
84 |
sort -u in > in2 |
uniqurl |
85 |
|
|
86 |
|
mirror_in |
87 |
|
|
88 |
|
# convert links in html |
89 |
|
bn=`basename $0` |
90 |
|
dir=`echo $0 | sed "s/$bn$//"` |
91 |
|
ls index.html* | xargs -i $dir/filter.pl {} |
92 |
|
mkdir orig |
93 |
|
mv index.html* orig/ |
94 |
|
|
|
mirror "-i in2" |
|