koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/misc/amazonratings get_ratings.pl,1.1,1.2


From: Chris Cormack
Subject: [Koha-cvs] CVS: koha/misc/amazonratings get_ratings.pl,1.1,1.2
Date: Fri, 05 Mar 2004 23:55:49 -0800

Update of /cvsroot/koha/koha/misc/amazonratings
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4665

Modified Files:
        get_ratings.pl 
Log Message:
Bugfix, now it actually does whats its supposed to.


Index: get_ratings.pl
===================================================================
RCS file: /cvsroot/koha/koha/misc/amazonratings/get_ratings.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** get_ratings.pl      6 Mar 2004 07:45:33 -0000       1.1
--- get_ratings.pl      6 Mar 2004 07:55:35 -0000       1.2
***************
*** 13,63 ****
  use C4::Context;
  
! my 
$url="http://www.amazon.com/exec/obidos/search-handle-url/index%3Dbooks%26field-isbn%3D";;
  
! my $dbh=C4::Context->dbh();
! 
! my $query="SELECT isbn,biblioitemnumber,biblionumber FROM biblioitems";
! my $sth=$dbh->prepare($query);
  $sth->execute();
! while (my $data=$sth->fetchrow_hashref()){
!   $data->{'isbn'}=~ s/\-//g;
!     $data->{'isbn'}=~ s/ +//g;
!     
! # append isbn 
! # isbn must appear without spaces or -
! 
! $url.=$data->{'isbn'};
! my $ua = LWP::UserAgent->new;
! my $content = $ua->get($url)->content;
! #print $content;
! 
! 
! my $rating;
! 
! if ($content=~ /alt="(.*?) out of 5 stars"/){
!     $rating=$1;
!     
!                }
! if ($rating){
!     # first check we dont already have a rating, if so, and its different 
update it
!     # otherwise insert a new rating
!     my $query2="SELECT * FROM ratings WHERE biblioitemnumber=?";
!     my $sth2=$dbh->prepare($query2);
!     $sth2->execute($data->{'biblioitemnumber'});
!     if (my $ratings=$sth2->fetchrow_hashref()){
!       if ($rating ne $ratings->{'rating'}){
!           my $query3="UPDATE ratings SET rating=? WHERE biblioitemnumber=?";
!           my $sth3=$dbh->prepare($query3);
!           $sth3->execute($rating,$data->{'biblioitemnumber'});
!           $sth3->finish();
!           }
!       }
!     else {
!       my $query3="INSERT INTO ratings (rating,biblioitemnumber,biblionumber) 
VALUES (?,?,?)";
!       my $sth3=$dbh->prepare($query3);
!       
$sth3->execute($rating,$data->{'biblioitemnumber'},$data->{'biblionumber'});
!       $sth3->finish();
!       }
!     $sth2->finish();
      }
      }
--- 13,70 ----
  use C4::Context;
  
! my $dbh = C4::Context->dbh();
  
! my $query =
! "SELECT isbn,biblioitemnumber,biblionumber FROM biblioitems where isbn is NOT 
NULL and isbn <> ''
!   group by isbn";
! my $sth = $dbh->prepare($query);
  $sth->execute();
! while ( my $data = $sth->fetchrow_hashref() ) {
!     $data->{'isbn'} =~ s/\-//g;
!     $data->{'isbn'} =~ s/ +//g;
! 
!     # append isbn 
!     # isbn must appear without spaces or -
!     my $url = 
"http://www.amazon.com/exec/obidos/search-handle-url/index%3Dbooks%26field-isbn%3D";;
!     $url .= $data->{'isbn'};
!     my $ua      = LWP::UserAgent->new;
!     my $content = $ua->get($url)->content;
! 
!     #print $content;
! 
!     my $rating;
! 
!     if ( $content =~ /alt="(.*?) out of 5 stars"/ ) {
!         $rating = $1;
! 
      }
+     if ($rating) {
+ 
+        # first check we dont already have a rating, if so, and its different 
update it
+         # otherwise insert a new rating
+         my $query2 = "SELECT * FROM ratings WHERE biblioitemnumber=?";
+         my $sth2   = $dbh->prepare($query2);
+         $sth2->execute( $data->{'biblioitemnumber'} );
+         if ( my $ratings = $sth2->fetchrow_hashref() ) {
+             if ( $rating ne $ratings->{'rating'} ) {
+                 my $query3 =
+                   "UPDATE ratings SET rating=? WHERE biblioitemnumber=?";
+                 my $sth3 = $dbh->prepare($query3);
+                 $sth3->execute( $rating, $data->{'biblioitemnumber'} );
+                 $sth3->finish();
+             }
+         }
+         else {
+             my $query3 =
+ "INSERT INTO ratings (rating,biblioitemnumber,biblionumber) VALUES (?,?,?)";
+             my $sth3 = $dbh->prepare($query3);
+             $sth3->execute(
+                 $rating, $data->{'biblioitemnumber'},
+                 $data->{'biblionumber'}
+             );
+             $sth3->finish();
+         }
+         $sth2->finish();
+ 
      }
+ }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]