#!/usr/bin/perl

system("renice 20 $$");
system("clear");

require "functions.pl";


my @months = (
	'January',
	'February',
	'March',
	'April',
	'May',
	'June',
	'July',
	'August',
	'September',
	'October',
	'November',
	'December'
);

my @monate = (
	"Januar",
	"Februar",
	"Maerz",
	"April",
	"Mai",
	"Juni",
	"Juli",
	"August",
	"September",
	"Oktober",
	"November",
	"Dezember"
);


&CACHE();
exit;


sub CACHE(){

	my $timeout	= "500";
	my $ua		= "Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; rv:1.6) Gecko/20040206 Firefox/1.0.1";

	my %CACHING = (
		
	
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/dezember-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=dezember-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/november-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=november-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/oktober-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=oktober-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/september-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=september-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/august-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=august-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/juli-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=juli-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/juni-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=juni-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/mai-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=mai-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/april-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=april-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/maerz-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=maerz-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/februar-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=februar-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/januar-2006.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=januar-2006",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/januar-2007.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=januar-2007",
	#	"/server/wwwroot/emule-bittorrent-newsarchive-deutsch/februar-2007.html" => "http://www.zoozle.net/emule-bittorrent-newsarchive-deutsch/index.php?date=februar-2007",
		
		"/server/wwwroot/emule-bittorrent-newsarchive-english/december-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=december-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/november-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=november-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/october-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=october-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/september-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=september-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/august-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=august-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/july-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=july-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/june-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=june-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/may-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=may-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/april-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=april-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/march-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=march-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/february-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=february-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/january-2006.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=january-2006",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/january-2007.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=january-2007",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/february-2007.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=february-2007",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/march-2007.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=march-2007",
		"/server/wwwroot/emule-bittorrent-newsarchive-english/april-2007.html" => "http://www.zoozle.org/emule-bittorrent-newsarchive-english/index.php?date=april-2007",
				
	);

	while( my ( $path, $url ) = each(%CACHING) ){
		my $page = &http_get($url, $timeout, $ua, );
		#sleep 200;
		unlink $path;

		if ( length($page) >= 1000 ) {
		
			unlink $path;
			open(WH,">$path") or die "CANNOT SAVE FILE";
			#binmode(WH);
				print WH $page;
				print WH "<center style=\"font-size: 9px; color:#888888\">Cached Version from : " . MySQLDateTime() . "</center>";
			close WH;

		} else {
			
			my $page = &http_get($url, $timeout, $ua, );
			
			if ( length($page) >= 1000 ) {

				unlink $path;
				open(WH,">$path") or die "CANNOT SAVE FILE";
					print WH $page;
					print WH "<center style=\"font-size: 9px; color:#888888\">Cached Version from : " . MySQLDateTime() . "</center>";
				close WH;

			};

		}; # if ( length($page) >= 1000 ) {
	
		print "I cached: $url\n";
	};

	return 1;

}; # sub CACHE(){}


sub MySQLDateTime() {

	my ( $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst ) = localtime(time);
	$year = $year+1900;
	$mon = $mon + 1;

	if ( length($mon) == 1 ) {
		$mon = "0". $mon;
	};
	if ( length($mday) == 1 ) {
		$mday = "0". $mday;
	};
	if ( length($sec) == 1 ) {
		$sec = "0". $sec;
	};
	if ( length($min) == 1 ) {
		$min = "0". $min;
	};
	if ( length($hour) == 1 ) {
		$hour = "0". $hour;
	};
	   
	return $year ."-". $mon ."-". $mday .' '. $hour .':'. $min .':'. $sec;
	
}; # sub MySQLDateTime() {}
