/[safari]/get_book.sh
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /get_book.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Mon Dec 15 09:33:29 2003 UTC (20 years, 4 months ago) by dpavlin
Branch: MAIN
Changes since 1.3: +15 -14 lines
File MIME type: application/x-sh
fix fix

1 #!/bin/sh
2
3 export http_proxy=http://proxy:8080
4
5 if [ -z "$1" ] ; then
6 echo "Usage: $0 ISBN"
7 exit 1
8 fi
9
10 isbn=$1;
11
12 wait=10
13
14 isbn2=`echo $isbn | sed 's/-//g'`
15
16 function mirror() {
17 wget -p -nH -nc -k \
18 --random-wait --wait=$wait -t 0 \
19 --load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt \
20 -U "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031206 Firebird/0.7" \
21 $1
22
23 # -D safari.oreilly.com \
24 # -A 0-201-41975-0 \
25 }
26
27 function geturl() {
28 hindent -s $1 | grep -i href | grep mode=[st][eo]c | \
29 sed -e 's/^.*<a.*href="//i' \
30 -e 's/".*//' -e 's/amp;//g' \
31 -e 's,^[^\?]*\?,http://safari.oreilly.com/,' \
32 -e 's/#$//' \
33 -e 's/\&srchText=//' \
34 -e 's/open=false/open=true/' | \
35 grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \
36 grep $2 | \
37 sort -u >> in
38 }
39
40 function uniqurl() {
41 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..."
61 geturl "index.html?XmlId=$isbn" $isbn
62 uniqurl
63
64 mirror_in
65
66 echo -n "extracting URLs [1]"
67 ls index.html* | while read file ; do
68 echo -n "."
69 geturl $file $isbn
70 done
71 echo
72
73 uniqurl
74
75 mirror_in
76
77 echo -n > in
78 echo -n "extracting URLs [2]"
79 ls index.html* | while read file ; do
80 echo -n "."
81 geturl $file $isbn
82 done
83
84 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

  ViewVC Help
Powered by ViewVC 1.1.26