Last active
January 30, 2016 16:21
-
-
Save Djent-/dd3adbbe0b15dbab17a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# COPYRIGHT PATRICK HURD 2016 RELEASED UNDER GPL VERSION 3 | |
# https://gist.github.com/Djent-/dd3adbbe0b15dbab17a0 | |
use warnings; | |
use strict; | |
my $DIRECTORY = ""; # where the dbin2 files are | |
my $PYLOCATION = ""; # where 1.py and 2.py are | |
my $MODSPEED1 = 2; # lower number is slower. | |
my $MODSPEED2 = 1; # lower number is faster. any positive integer is good. 0 for turbo-nuclear mode | |
my $DEBUG = 1; # toggle to log debug information | |
my $files = 0; | |
open(LOG, ">py_all.log") if $DEBUG; | |
my $time = localtime(); | |
print LOG "$time\n" if $DEBUG; | |
opendir(DIR, $DIRECTORY) or die $!; | |
while (my $file = readdir(DIR)) { | |
if ($file =~ /dbin2$/) { | |
chomp($file); | |
print LOG "Processing\t$file\n" if $DEBUG; | |
my $command = $PYLOCATION . "/1.py $file"; | |
my $output = `$command`; | |
sleep($MODSPEED2) if ($files % $MODSPEED1 == 0); | |
$files++; | |
} | |
} | |
print("1.py processed $files files\n"); | |
print LOG "1.py processed $files files\n" if $DEBUG; | |
print LOG "Slept for total of " . $MODSPEED2 * $files / $MODSPEED1 . " seconds\n" if $DEBUG; | |
$files = 0; | |
closedir(DIR) or die $!; | |
opendir(DIR, $DIRECTORY) or die $!; | |
# loop through directories created by 1.py | |
while (my $dir = readdir(DIR)) { | |
print LOG "Processing\t$dir\n" if $DEBUG; | |
if ($dir =~ /^\w\d\d\d$/) { # LXXX directory | |
print LOG "Opening\t$dir\n" if $DEBUG; | |
opendir(TEMPDIR, $dir) or die $!; | |
# loop through files in LXXX directory | |
while (my $file = readdir(TEMPDIR)) { | |
if ($file =~ /sdl2$/) { | |
print LOG "Processing\t$dir/$file\n" if $DEBUG; | |
my $command = $PYLOCATION . "/2.py $dir/$file"; | |
my $output = `$command`; | |
sleep($MODSPEED2) if ($files % $MODSPEED1 == 0); | |
$files++; | |
} | |
} | |
closedir(TEMPDIR) or die $!; | |
# concatenate output .txt files | |
# commissioned by MGDanon | |
# for two (2) slices of pizza | |
print LOG "Opening $dir for concatenation\n" if $DEBUG; | |
opendir(TEMPDIR, $dir) or die $!; | |
my $output = ""; | |
while (my $file = readdir(TEMPDIR)) { | |
if ($file =~ /txt$/) { | |
chomp($file); | |
print LOG "Processing\t$dir/$file\n" if $DEBUG; | |
open(FH, "<$dir/$file") or die "No such file '$dir/$file'"; | |
my @lines = <FH>; | |
close(FH) or die $!; | |
unlink "$dir/$file" or die $!; | |
$file =~ s/.txt//; | |
unlink "$dir/$file" or die $1; | |
print LOG "Adding $#lines line(s) to output\n" if $DEBUG; | |
foreach my $line (@lines) { | |
$output = "$output$line\n"; | |
} | |
} | |
} | |
closedir(TEMPDIR) or die $!; | |
# write to output | |
open(OUT, ">$dir/$dir.txt") or die $!; | |
print OUT $output; | |
close(OUT) or die $!; | |
my $length = length($output); | |
print LOG "Wrote $length chars to output\n" if $DEBUG; | |
} | |
} | |
closedir(DIR) or die $!; | |
print("2.py processed $files files\n"); | |
print LOG "2.py processed $files files\n" if $DEBUG; | |
print LOG "Slept for total of " . $MODSPEED2 * $files * 2 / $MODSPEED1 . " seconds\n" if $DEBUG; | |
$time = localtime(); | |
print LOG "$time\n" if $DEBUG; | |
close(LOG) if $DEBUG; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment