/[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

Diff of /get_book.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by dpavlin, Sat Jan 17 16:25:38 2004 UTC revision 1.11 by dpavlin, Thu Jun 17 19:43:24 2004 UTC
# Line 1  Line 1 
1  #!/bin/sh  #!/bin/sh
2    
3  # proxy settings (same as in firebird)  # proxy settings (same as in firebird)
4  ( ping proxy 2>&1 ) >/dev/null && export http_proxy=http://proxy:8080  fping -q proxy && export http_proxy=http://proxy:8080 ||
5    fping -q proxy.lan && export http_proxy=http://proxy.lan:8080
6  # user agent (same as in firebird)  # user agent (same as in firebird)
7  ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031225 Firebird/0.7"  ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040506 Firefox/0.8"
8    cookie_file="cookie.txt"
9    
10  # wait between pages  # wait between pages
11  export wait=120  export wait=120
12    
13    if [ ! -z "$http_proxy" ] ; then
14            echo "Using proxy $http_proxy"
15    fi
16    
17  if [ -z "$1" ] ; then  if [ -z "$1" ] ; then
18          echo "Usage: $0 ISBN"          echo "Usage: $0 ISBN"
# Line 23  if [ -e orig ] ; then Line 28  if [ -e orig ] ; then
28          mv orig/* .          mv orig/* .
29          rm -Rf orig          rm -Rf orig
30    
31          grep -l 'promo.asp' * | xargs -i rm -v {}          grep -l 'promo.asp' * | xargs -i rm {}
32            grep -l 'This is only a preview of the full book' * | xargs -i rm {}
33  fi  fi
34    
35  isbn=$1;  isbn=`echo $1 | sed 's/-//g' | tr '[a-z]' '[A-Z]'`
   
 isbn2=`echo $isbn | sed 's/-//g'`  
36    
37  function mirror() {  function mirror() {
38    
# Line 37  function mirror() { Line 41  function mirror() {
41          file=`echo $url | sed -e s,http://[^?]*?,index.html?, -e s,#.*$,, -e s,/,%2F,g`          file=`echo $url | sed -e s,http://[^?]*?,index.html?, -e s,#.*$,, -e s,/,%2F,g`
42          if [ -e "$file" ] ; then          if [ -e "$file" ] ; then
43  #               echo "skip $url"  #               echo "skip $url"
44                    echo -n "."
45                  return                  return
46          fi          fi
47    
48            cookie=""
49          if echo $url | grep '/index' >/dev/null ; then          if echo $url | grep '/index' >/dev/null ; then
                 cookies=""  
50                  echo -n "no login (index) "                  echo -n "no login (index) "
51          elif echo $url | grep 'mode=toc' >/dev/null ; then          elif echo $url | grep 'mode=toc' >/dev/null ; then
                 cookies=""  
52                  echo -n "no login (toc) "                  echo -n "no login (toc) "
53          else          else
54                  cookies="--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt"                  if [ ! -e $cookie_file ] ; then
55                  echo -n "with login "                          echo "cookies file $cookie_file doesn't exits! Please create it."
56                            echo "It should be in format:"
57                            echo "Cookie: Site=UICode=&Portal=oreilly&GUID=..."
58                            exit 1
59                    fi
60                    read cookie < $cookie_file
61                    if [ -z "$cookie" ] ; then
62                            echo "Empty cookie file $cookie_file !"
63                            exit 1
64                    fi
65          fi          fi
         echo $url  
66    
67          wget -p -nH -nc -k \          if [ -z "$cookie" ] ; then
68                  -t 1 -U "$ua" \                  echo "$url [no cookie]"
69                  $cookies $url          else
70                    echo "$url [with cookie]"
71            fi
72    
73  #       -D safari.oreilly.com \          wget -q -p -nH -nc -k -t 1 -U "$ua" --cookies=off --header="$cookie" $url
74  #       -A 0-201-41975-0 \          perl -e '$t=rand($ENV{wait} || 120);print "sleep for $t sec.\n"; sleep($t);'
75    
         perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);'  
76  }  }
77    
78  function geturl() {  function geturl() {
# Line 67  function geturl() { Line 80  function geturl() {
80          sed -e 's/^.*<a.*href="//i' \          sed -e 's/^.*<a.*href="//i' \
81                  -e 's/".*//' -e 's/amp;//g' \                  -e 's/".*//' -e 's/amp;//g' \
82                  -e 's,^[^\?]*\?,http://safari.oreilly.com/,' \                  -e 's,^[^\?]*\?,http://safari.oreilly.com/,' \
83                  -e 's/#$//' \                  -e 's/#.*$//' \
84                  -e 's/\&srchText=//' \                  -e 's/\&srchText=//' \
85                  -e 's/open=false/open=true/' | \                  -e 's/open=false/open=true/' | \
86                  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' | \
87                  grep $2 | \                  grep -i "xmlid=[0-9A-Za-z\-][0-9A-Za-z\-]*" | \
88                  grep -v "$2/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" | \                  grep -vi "xmlid=[0-9A-Za-z\-]*/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" | \
89                  sort -u >> in                  sort -u >> in
90  }  }
91    
# Line 80  function uniqurl() { Line 93  function uniqurl() {
93          mv in in.tmp          mv in in.tmp
94          grep -v 'view=[A-Z]' in.tmp | sort -u > in          grep -v 'view=[A-Z]' in.tmp | sort -u > in
95          grep 'view=[A-Z].*/index' in.tmp | sort -u >> in          grep 'view=[A-Z].*/index' in.tmp | sort -u >> in
96            links=`wc -l in | cut -d" " -f1`
97            echo "found $links unique links"
98  }  }
99    
100  function mirror_in() {  function mirror_in() {
# Line 101  function mirror_in() { Line 116  function mirror_in() {
116                          echo "WARNING: your safari session is disabled. Aborting."                          echo "WARNING: your safari session is disabled. Aborting."
117                          exit 1                          exit 1
118                  fi                  fi
119    
120                    if grep -i 'This is only a preview of the full book' `ls -t index.html* | head -3` >/dev/null ; then
121                            echo "WARNING: you didn't add this book to your bookshelf!"
122                            exit 1
123                    fi
124          done          done
125            echo
126  }  }
127    
128  echo -n > in  echo -n > in
129  mirror "http://safari.oreilly.com/?XmlId=$isbn"  mirror "http://safari.oreilly.com/$isbn"
130    echo
131    
132  echo "extract URLs from first page..."  file=`ls *index.html?XmlId=*`
133  geturl "index.html?XmlId=$isbn" $isbn  isbn=`echo $file | cut -d= -f2`
134    echo "extract URLs from first page $file... [$isbn]"
135    geturl $file $isbn
136  uniqurl  uniqurl
137    
138  mirror_in  mirror_in

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.26