#!/usr/bin/perl

# /root/zoozle/new-bots/emule-newsbot/TorrentNewsCrawler.pl

use IO::Handle;
require "/root/zoozle/new-bots/torrent-newsbot/functions.pl";


my $EmuleStoreFlatFile = "/root/zoozle/new-bots/emule_news.txt";
unlink $EmuleStoreFlatFile;

my %BotsDE = (
	"1" => 'saug.pl',
	"2" => 'titan.pl',
	"3" => 'eselfilme.pl',
	"4" => 'goldesel.pl',
	"5" => 'portal.pl',
#	"6" => '.pl',
#	"7" => '',
#	"8" => '',
);

my %BotsEN = (
	"1" => 'tv.pl',
#	"2" => 'share.pl',
	"3" => 'fuck.pl',
	"4" => 'reactor.pl',
#	"5" => '.pl',
#	"6" => 'a.pl',
#	"7" => '.pl',
#	"8" => '.pl',
#	"9" => '.pl',
#	"10" => '.pl',
#	"11" => '',
);


open(TORRENT,">$EmuleStoreFlatFile") or warn;
		TORRENT->autoflush(1);
		TORRENT->blocking(0);
		binmode TORRENT, ":utf8";
		flock(TORRENT, 2);

while( my ($key,$val) = each(%BotsDE) ) {

	my $Content = '';
	$Content = `/usr/bin/perl /root/zoozle/new-bots/emule-newsbot/de/$val`;
	print TORRENT "$Content\n";
	
}; # while

while( my ($key,$val) = each(%BotsEN) ) {

	my $Content = '';
	$Content = `/usr/bin/perl /root/zoozle/new-bots/emule-newsbot/en/$val`;
	print TORRENT "$Content\n";
	
}; # while

close TORRENT;




open(WH,"+>>/root/spiderlog.txt");
my $Load = &LoadCheck();
print WH getHumanTime()." $0 Start Adding to SQL - $Load\n";

&AddContentToSqlEMULE($EmuleStoreFlatFile);

my $Load = &LoadCheck();
print WH getHumanTime()." $0 End Adding to SQL - $Load\n";
close WH;



sub getHumanTime {
	my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat,
    $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) = localtime(time);
	my $CTIME_String = localtime(time);
	$Monat+=1;
	$Jahrestag+=1;
	$Monat = $Monat < 10 ? $Monat = "0".$Monat : $Monat;
	$Monatstag = $Monatstag < 10 ? $Monatstag = "0".$Monatstag : $Monatstag;
	$Stunden = $Stunden < 10 ? $Stunden = "0".$Stunden : $Stunden;
	$Minuten = $Minuten < 10 ? $Minuten = "0".$Minuten : $Minuten;
	$Sekunden = $Sekunden < 10 ? $Sekunden = "0".$Sekunden : $Sekunden;
	$Jahr+=1900;
	my @Wochentage = ("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag");
	my @Monatsnamen = ("","Januar","Februar","M&auml;rz","April","Mai","Juni",
	           "Juli","August","September","Oktober","November","Dezember");
	my $finale="$Wochentage[$Wochentag], $Monatstag. $Monatsnamen[$Monat] $Jahr, $Stunden:$Minuten:$Sekunden";
	return $finale;	

}

sub LoadCheck(){

	open(LOAD,"/proc/loadavg");
		
		my $load_tmp = <LOAD>;
		my ($load1,$load2,$load3)=split(" ", $load_tmp);
	
	close LOAD;

	return "$load1,$load2,$load3";

}; # sub LoadCheck(){