#!/usr/bin/perl

# /root/zoozle/new-bots/torrent-newsbot/TorrentNewsCrawler.pl
## perl -MCPAN -e 'install "XML::TreePP"'

use IO::Handle;
require "/root/zoozle/new-bots/torrent-newsbot/functions.pl";


my $TorrentStoreFlatFile = "/root/zoozle/new-bots/torrent_news.txt";
unlink $TorrentStoreFlatFile;

my %BotsDE = (
#	"1" => 'torrentto.pl',
	"2" => 'bitreactor.pl',
	"3" => 'deluxe.pl',
	"4" => 'more.pl',
	"5" => 'speed.pl',
	"6" => 'sex.pl',	# http://www.bitbull.to/ -> LOGIN für torrents required! -> komplett löschen alle Links in DB und nicht mehr indizieren
#	"7" => '',
#	"8" => '',
);

my %BotsEN = (
	"1" => 'mybit.pl',
	"2" => 'pirate.pl',
	"3" => 'demon.pl',
	"4" => 'iso.pl',
	"5" => 'box.pl',
	"6" => 'mega.pl',
	"7" => 'bitjunkie.pl',
	"8" => 'reactor.pl',
	"9" => 'mininova.pl',
	"10" => 'snarf.pl',
#	"11" => '',
);


open(TORRENT,">$TorrentStoreFlatFile") 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/torrent-newsbot/de/$val`;
	print TORRENT "$Content\n";
	
}; # while

while( my ($key,$val) = each(%BotsEN) ) {

	my $Content = '';
	$Content = `/usr/bin/perl /root/zoozle/new-bots/torrent-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";

&AddContentToSqlTORRENT($TorrentStoreFlatFile);

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(){