/[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.8 by dpavlin, Tue Feb 17 19:06:10 2004 UTC revision 1.12 by dpavlin, Wed Jul 21 13:58:35 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  fping proxy && export http_proxy=http://proxy:8080  fping -q proxy && export http_proxy=http://proxy:8080
5    if [ -z "$http_proxy" ] ; then
6            fping -q proxy.lan && export http_proxy=http://proxy.lan:8080
7    fi
8  # user agent (same as in firebird)  # user agent (same as in firebird)
9  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"
10    cookie_file="cookie.txt"
11    
12  # wait between pages  # wait between pages
13  export wait=120  export wait=120
14    
15    if [ ! -z "$http_proxy" ] ; then
16            echo "Using proxy $http_proxy"
17    fi
18    
19  if [ -z "$1" ] ; then  if [ -z "$1" ] ; then
20          echo "Usage: $0 ISBN"          echo "Usage: $0 ISBN"
# Line 27  if [ -e orig ] ; then Line 34  if [ -e orig ] ; then
34          grep -l 'This is only a preview of the full book' * | xargs -i rm {}          grep -l 'This is only a preview of the full book' * | xargs -i rm {}
35  fi  fi
36    
37  isbn=$1;  isbn=`echo $1 | sed 's/-//g' | tr '[a-z]' '[A-Z]'`
   
 isbn2=`echo $isbn | sed 's/-//g'`  
38    
39  function mirror() {  function mirror() {
40    
# Line 42  function mirror() { Line 47  function mirror() {
47                  return                  return
48          fi          fi
49    
50            cookie=""
51          if echo $url | grep '/index' >/dev/null ; then          if echo $url | grep '/index' >/dev/null ; then
                 cookies=""  
52                  echo -n "no login (index) "                  echo -n "no login (index) "
53          elif echo $url | grep 'mode=toc' >/dev/null ; then          elif echo $url | grep 'mode=toc' >/dev/null ; then
                 cookies=""  
54                  echo -n "no login (toc) "                  echo -n "no login (toc) "
55          else          else
56                  cookies="--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt"                  if [ ! -e $cookie_file ] ; then
57                  echo -n "with login "                          echo "cookies file $cookie_file doesn't exits! Please create it."
58                            echo "It should be in format:"
59                            echo "Cookie: Site=UICode=&Portal=oreilly&GUID=..."
60                            exit 1
61                    fi
62                    read cookie < $cookie_file
63                    if [ -z "$cookie" ] ; then
64                            echo "Empty cookie file $cookie_file !"
65                            exit 1
66                    fi
67          fi          fi
         echo $url  
68    
69          wget -p -nH -nc -k \          if [ -z "$cookie" ] ; then
70                  -t 1 -U "$ua" \                  echo "$url [no cookie]"
71                  $cookies $url          else
72                    echo "$url [with cookie]"
73            fi
74    
75  #       -D safari.oreilly.com \          wget -q -p -nH -nc -k -t 1 -U "$ua" --cookies=off --header="$cookie" $url
76  #       -A 0-201-41975-0 \          perl -e '$t=rand($ENV{wait} || 120);print "sleep for $t sec.\n"; sleep($t);'
77    
         perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);'  
78  }  }
79    
80  function geturl() {  function geturl() {
# Line 72  function geturl() { Line 85  function geturl() {
85                  -e 's/#.*$//' \                  -e 's/#.*$//' \
86                  -e 's/\&srchText=//' \                  -e 's/\&srchText=//' \
87                  -e 's/open=false/open=true/' | \                  -e 's/open=false/open=true/' | \
88                  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&n=1&d=1&p=1&a=0' | \
89                  grep $2 | \                  grep -i "xmlid=[0-9A-Za-z\-][0-9A-Za-z\-]*" | \
90                  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]" | \
91                  sort -u >> in                  sort -u >> in
92  }  }
93    
94  function uniqurl() {  function uniqurl() {
95          mv in in.tmp          mv in in.tmp
96          grep -v 'view=[A-Z]' in.tmp | sort -u > in          grep -v 'view=[A-Z]' in.tmp | grep 'a=0$' | sort -u > in
97          grep 'view=[A-Z].*/index' in.tmp | sort -u >> in          grep 'view=[A-Z].*/index' in.tmp | grep 'a=0$' | sort -u >> in
98          links=`wc -l in | cut -d" " -f1`          links=`wc -l in | cut -d" " -f1`
99          echo "found $links unique links"          echo "found $links unique links"
100  }  }
# Line 115  function mirror_in() { Line 128  function mirror_in() {
128  }  }
129    
130  echo -n > in  echo -n > in
131  mirror "http://safari.oreilly.com/?XmlId=$isbn"  mirror "http://safari.oreilly.com/$isbn"
132  echo  echo
133    
134  echo "extract URLs from first page..."  file=`ls *index.html?XmlId=*`
135  geturl "index.html?XmlId=$isbn" $isbn  isbn=`echo $file | cut -d= -f2`
136    echo "extract URLs from first page $file... [$isbn]"
137    geturl $file $isbn
138  uniqurl  uniqurl
139    
140  mirror_in  mirror_in

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.26