#!/usr/bin/perl use DBI; use HTTP::Request (); use LWP::UserAgent (); use strict; ################################################## ###################### ## DATABASE CODE!! my $dbname = 'everydevel'; ##Name of DATABASE my $key_database_name = "node"; ##--TABLE-- name that contains all data for a node my $database_node_id = "node_id"; ##--name of the row in Table-- that contains a given node's ID my $database_node_title = "title"; ##--name of the row in Table-- that contains a given node's title my $database_node_amazon_code = "amazon_code"; ##--name of row in table-- that contains all the amazon code my $cached_database_name = "cached_start_id"; ##--TABLE-- name that contains all data for last cached node's ID my $db_cached_stop_start = "last_id"; ##--name of the row in Table-- that contains the node ID of the last cached node my $max_allowed_downloads = 1000; #No. of node's you want to be updated my ($dbuser, $dbpasswd) = ('root', ''); my $dbh = DBI->connect("DBI:mysql:$dbname", $dbuser, $dbpasswd) or die "can't connect: $DBI::errstr\n"; my $start_node_id = get_start_id(); my $stop_node_id = put_stop_id(); my $node_id_string = "SELECT $database_node_id FROM $key_database_name limit $start_node_id, $max_allowed_downloads"; my $sth_id = $dbh->prepare($node_id_string); $sth_id->execute(); my $node_title_string = "SELECT $database_node_title FROM $key_database_name order by $database_node_id limit $start_node_id, $max_allowed_downloads"; my $sth_title = $dbh->prepare($node_title_string); $sth_title->execute(); while ((my $row = $sth_id->fetchrow_arrayref) && (my $row_title = $sth_title->fetchrow_arrayref)) { my $call_code = get(@$row_title); my $query = "UPDATE $key_database_name SET $database_node_amazon_code=".$dbh->quote($call_code)." where $database_node_id='@$row'"; my $check = $dbh->prepare($query); $check->execute; $check->finish; } sub get_start_id { my $sub_start_node_grabbed_id; my $sub_start_node_id = "SELECT $db_cached_stop_start FROM $cached_database_name"; my $sub_start_node_sth_id = $dbh->prepare($sub_start_node_id); $sub_start_node_sth_id->execute(); while ($sub_start_node_grabbed_id = $sub_start_node_sth_id->fetchrow_arrayref) { if (@$sub_start_node_grabbed_id == "") { my $returnable_sub_start_node_grabbed_id = $sub_start_node_grabbed_id->[0]; my $sub_start_node_grabbed_id_insert = "0"; my $sub_query = "UPDATE $cached_database_name SET $db_cached_stop_start='$sub_start_node_grabbed_id_insert'"; my $sub_check = $dbh->prepare($sub_query); $sub_check->execute; $sub_check->finish; return $returnable_sub_start_node_grabbed_id; } else { my $returnable_sub_start_node_grabbed_id = $sub_start_node_grabbed_id->[0]; return $returnable_sub_start_node_grabbed_id; } } } sub put_stop_id { my $sub_stop_node_grabbed_id; my $sub_start_node_grabbed_id; my $sub_start_node_id = "SELECT $db_cached_stop_start FROM $cached_database_name"; my $sub_start_node_sth_id = $dbh->prepare($sub_start_node_id); $sub_start_node_sth_id->execute(); while ($sub_stop_node_grabbed_id = $sub_start_node_sth_id->fetchrow_arrayref) { my $sub_todo_rows = get_todo_rows(); if ($sub_todo_rows <= $max_allowed_downloads) { $sub_stop_node_grabbed_id = "0"; my $sub_query = "UPDATE $cached_database_name SET $db_cached_stop_start='$sub_stop_node_grabbed_id'"; my $sub_check = $dbh->prepare($sub_query); $sub_check->execute; $sub_check->finish; $sub_stop_node_grabbed_id = $sub_todo_rows; my $return = $sub_stop_node_grabbed_id + $sub_todo_rows; return $return; } else { my $sub_new_stop_node_grabbed_id; $sub_new_stop_node_grabbed_id = @$sub_stop_node_grabbed_id[0] + $max_allowed_downloads; my $sub_query = "UPDATE $cached_database_name SET $db_cached_stop_start='$sub_new_stop_node_grabbed_id'"; my $sub_check = $dbh->prepare($sub_query); $sub_check->execute; $sub_check->finish; return $sub_new_stop_node_grabbed_id; } } } #### #Taken out to ensure a quick response time #### #sub get_todo_rows { # print "BEGIN\n"; # my $sub_stop_node_id = $start_node_id + $max_allowed_downloads; # my $sub_count_rows = 0; # my $temp_sub_node_id_string = "SELECT $database_node_id FROM $key_database_name"; # my $temp_sub_sth_id = $dbh->prepare($temp_sub_node_id_string); # $temp_sub_sth_id->execute(); # my $temp_sub_count_rows = 0; # while ((my $temp_sub_row = $temp_sub_sth_id->fetchrow_arrayref)) { # $temp_sub_count_rows++; # my $sub_node_id_string = "SELECT $database_node_id FROM $key_database_name limit $start_node_id, $temp_sub_count_rows"; # my $sub_sth_id = $dbh->prepare($sub_node_id_string); # $sub_sth_id->execute(); # while ((my $sub_row = $sub_sth_id->fetchrow_arrayref)) { # $sub_count_rows++; # } # } # print "END\n"; # return $sub_count_rows; #} sub get_todo_rows { my $temp_sub_node_id_string = "select count(*) from $key_database_name"; my $temp_sub_sth_id = $dbh->prepare($temp_sub_node_id_string); $temp_sub_sth_id->execute(); while (my $temp_cal = $temp_sub_sth_id->fetchrow_arrayref) { my $todo_rows = @$temp_cal[0] - $start_node_id; return $todo_rows; } } ################################################## ###################### ## AMAZON CODE!! sub get { my $node_id = @_[0]; my $count_links = 0; #starting point of number of links you want on your site (0) will be 1 per book,vhs,dvd,etc. my $Associates_Id = "everything208"; ## Change this code my $xml = keywords($node_id, "books"); # or: my $xml_music = keywords_music($node_id, "music"); my $xml_vhs = keywords_vhs($node_id, "vhs"); my $xml_dvd = keywords_dvd($node_id, "dvd"); my @p = parse_xml($xml); my @q = parse_xml_music($xml_music); my @r = parse_xml_vhs($xml_vhs); my @s = parse_xml_dvd($xml_dvd); ##Begin Table Code my $str.="
| ".$p->{'author'}." "."".$p->{'title'}." ".$p->{'binding'}." List:".$p->{'list_price'}." Amazon:".$p->{'our_price'}." | |
| ".$q->{'author'}." "."".$q->{'title'}." ".$q->{'binding'}." List:".$q->{'list_price'}." Amazon:".$q->{'our_price'}." | |
| ".$r->{'author'}." "."".$r->{'title'}." ".$r->{'binding'}." List:".$r->{'list_price'}." Amazon:".$r->{'our_price'}." | |
| ".$s->{'author'}." "."".$s->{'title'}." ".$s->{'binding'}." List:".$s->{'list_price'}." Amazon:".$s->{'our_price'}." |