#!/usr/bin/perl # Copyright (c) 2004 Alan W. Mahoney. All rights reserved. # This program is free software. You may modify and/or # distribute it under the same terms as Perl itself. # This copyright notice must remain attached to the file. use warnings; use strict; use lib '/home/mahoney/usr/src/kolbot/'; use DBI; use KoLBot; use KoLBot::Items; use KoLBot::FileStateManager; use POSIX qw ( floor ); my $VERSION = 0.1; my $config = { statedir => '/tmp/mallbot', owner => 'Fnord7', # delay => 60, logfile_base => '/home/mahoney/mybots/logs/mallbot', bot => { site => ['http://www.kingdomofloathing.com/', 'http://www2.kingdomofloathing.com/', 'http://www3.kingdomofloathing.com/',], url_i => 0, user => 'mallbot', user_id => 213349, password => '******', timeout => 180, # Default timeout timeout_login => 180, # Timeout when logging in channel => 'clan', # Be nice to the logs agent => "mallbot/$VERSION", cookie_file => "/home/mahoney/mybots/mallbot.cookies.txt", }, }; # seconds between item lookups my $time_delta = 15; my $items = new KoLBot::Items(config => { file => '/home/mahoney/mybots/items.txt'}); $items->init; # our $sm = new KoLBot::FileStateManager(config => # { path => $config->{statedir} } ); my $bot = KoLBot->new(config => $config->{bot},items=>$items); # pull from items database my $max_item_id = 1200; # my $max_item_id = 3; $bot->login(); # my $state = $sm->get('mallbot','state'); # $sm->set("mallbot","state",$state); my $start_time = time(); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($start_time); my $filename = $config->{logfile_base} . (1900+$year) . ((($mon+1) < 10)?'0':'') . ($mon + 1) . ((($mday ) < 10)?'0':'') . ($mday ) . '.log'; open (LOGFILE, '>>',$filename) or die 'can\'t open file ' . $filename; REMALL: { eval { $bot->ensure( sub { # find the items for my $item_id (1..$max_item_id) { my $item = $items->get_item(id => $item_id); next unless($item); if(time() < $start_time + $item_id * $time_delta) { print "waiting for the next item\n"; sleep($start_time + $item_id * $time_delta - time()); } # run the query # to log # print LOGFILE "# $item->{name}\n"; # ITEM SPECIFIC my $whichitem = '"' . $item->{name} . '"'; $whichitem =~ s/newbiesport/newbiesport™/; $whichitem =~ s/jabanero/jaba˜ero/; my $results = $bot->search_mall(whichitem => $whichitem, cheaponly => 1, shownum => 99999); for(@$results) { my $time = time(); if(lc($_->{name}) eq lc($item->{name})) { print LOGFILE $time, " ",$item->id," ",$_->{store}," ",$_->{limit}, " ",$_->{number}," ",$_->{price},"\n"; } else { # it's not the right item. } } } }); }; print $@,"\n" if $@; # sleep 180, redo REMALL if $@ =~ /^SEARCH_DOWN/; } close LOGFILE; system('/usr/bin/gzip',$filename); system('/bin/cp',$filename . '.gz','/home/mahoney/public_html/kolbot/mallbotdata/');