[PerlWikiBot] SF.net SVN: perlwikibot: [27] trunk
Status: Pre-Alpha
Brought to you by:
rotemliss
From: <rot...@us...> - 2006-09-16 15:12:22
|
Revision: 27 http://svn.sourceforge.net/perlwikibot/?rev=27&view=rev Author: rotemliss Date: 2006-09-16 08:12:13 -0700 (Sat, 16 Sep 2006) Log Message: ----------- Comparing diff of times. Modified Paths: -------------- trunk/bot.pl trunk/config/configure.sample trunk/includes/functions.pm Modified: trunk/bot.pl =================================================================== --- trunk/bot.pl 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/bot.pl 2006-09-16 15:12:13 UTC (rev 27) @@ -6,6 +6,7 @@ # Libraries use LWP::UserAgent; +use Time::Local; use includes::actions; use includes::dump; use includes::functions; Modified: trunk/config/configure.sample =================================================================== --- trunk/config/configure.sample 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/config/configure.sample 2006-09-16 15:12:13 UTC (rev 27) @@ -5,9 +5,6 @@ use warnings; use strict; -# Libraries -use Time::local; - # Available servers and details about them, the bot should work on our %servers = ( "server" => "http://www.server.com", @@ -57,7 +54,7 @@ "action" => "מחליף שיחות אנונימיות", ); # Summary/reason sent about the action our %minimumTimes = ( - "action" => timegm( 0, 0, 0, 1, 1 - 1, 1970 - 1900 ), -); # The minimum diff between the current time and the last edit time + "action" => timegm( 0, 0, 0, 1, 1 - 1, 0 + 70 ), +); # The minimum diff between the current time and the last edit time (use: seconds, minutes, hours, day in month, month, year number; 1 January 0 00:00:00 means no minimum time, 2 January 0 00:00:00 means that the last edit should be at least one day old, etc.; edit only the first numbers, as the second ones are used for compatibility to the function) return 1; Modified: trunk/includes/functions.pm =================================================================== --- trunk/includes/functions.pm 2006-09-16 14:38:57 UTC (rev 26) +++ trunk/includes/functions.pm 2006-09-16 15:12:13 UTC (rev 27) @@ -58,7 +58,7 @@ $tempCounter = 0; for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { my $wantedText = $configure::texts{ $pagePossibleActions[$i] }; - if ($$text =~ /$wantedText/) { + if ( $$text =~ /$wantedText/ ) { $tempTextArray[$tempCounter++] = $pagePossibleActions[$i]; } } @@ -69,6 +69,26 @@ next; } + # Check if the page last edit is after the minimal time + my @tempLastEditArray; + my $lastEdit = $page->timestamp; + $lastEdit =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; + $lastEdit = main::timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); + my $betweenTime = time() - $lastEdit; + $tempCounter = 0; + for ( my $i = 0; $i <= $#pagePossibleActions; $i++ ) { + my $minimumTime = $configure::minimumTimes{ $pagePossibleActions[$i] }; + if ( $betweenTime > $minimumTime ) { + $tempLastEditArray[$tempCounter++] = $pagePossibleActions[$i]; + } + } + + # Continue if there are no matching pages + @pagePossibleActions = @tempLastEditArray; + if ( $#pagePossibleActions < 0 ) { + next; + } + # All the previous checks were OK - add the page, using the first available action $matchingPages[$counter++] = $title; $matchingPages[$counter++] = $pagePossibleActions[0]; @@ -78,36 +98,6 @@ return @matchingPages; } -# Get page last edit -# TODO: Move to getMatchingPages -sub getPageLastEdit { - # Get parameters - my ( $xmlFile, $title ) = @_; - utf8::decode( $title ); - - # Get the pages - my $pages = mwdump->new($xmlFile); - - # Can use only "first-letter", which is also the only currently known value, - # but there could be more in the future - if ( $pages->case ne "first-letter" ) { - die "Unable to handle any case setting besides \"first-letter\".\n"; - } - - # Searching for the page, and getting its timestamp - my $lastEditTimestamp = "0"; - while ( $lastEditTimestamp eq "0" && ( my $page = $pages->page ) ) { - if ( $title eq $page->title ) { - $lastEditTimestamp = $page->timestamp; - } - } - - # Check the time by RegExp - $lastEditTimestamp =~ /([\d]+)-([\d]+)-([\d]+)T([\d]+):([\d]+):([\d]+)Z/; - - return timegm( $6, $5, $4, $3, $2 - 1, $1 - 1900 ); -} - # Filter actions list to the specified script server sub filterActionsList { # Get parameters This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |