Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use v6;
- use GTK::Simple;
- use GTK::Simple::App;
- use GTK::Simple::FileChooserButton;
- my @year = ("Janeiro","Fevereiro","Mar�o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
- my @month = ();
- sub monthName($month, $cnt, $fh2) {
- #cases for month 1
- if $cnt == 0 and $month == 1 { $fh2.print(@year[1] ~";"); } elsif $cnt == 1 and $month == 1 { $fh2.print(@year[2] ~";"); }
- elsif $cnt == 2 and $month == 1 { $fh2.print(@year[3]); }
- #cases for month 2
- elsif $cnt == 0 and $month == 2 { $fh2.print(@year[2] ~";"); } elsif $cnt == 1 and $month == 2 { $fh2.print(@year[3] ~";"); }
- elsif $cnt == 2 and $month == 2 { $fh2.print(@year[4]); }
- #cases for month 3
- elsif $cnt == 0 and $month == 3 { $fh2.print(@year[3] ~";"); } elsif $cnt == 1 and $month == 3 { $fh2.print(@year[4] ~";"); }
- elsif $cnt == 2 and $month == 3 { $fh2.print(@year[5]); }
- #cases for month 4
- elsif $cnt == 0 and $month == 4 { $fh2.print(@year[4] ~";"); } elsif $cnt == 1 and $month == 4 { $fh2.print(@year[5] ~";"); }
- elsif $cnt == 2 and $month == 4 { $fh2.print(@year[6]); }
- #cases for month 5
- elsif $cnt == 0 and $month == 5 { $fh2.print(@year[5] ~";"); } elsif $cnt == 1 and $month == 5 { $fh2.print(@year[6] ~";"); }
- elsif $cnt == 2 and $month == 5 { $fh2.print(@year[7]); }
- #cases for month 6
- elsif $cnt == 0 and $month == 6 { $fh2.print(@year[6] ~";"); } elsif $cnt == 1 and $month == 6 { $fh2.print(@year[7] ~";"); }
- elsif $cnt == 2 and $month == 6 { $fh2.print(@year[8]); }
- #cases for month 7
- elsif $cnt == 0 and $month == 7 { $fh2.print(@year[7] ~";"); } elsif $cnt == 1 and $month == 7 { $fh2.print(@year[8] ~";"); }
- elsif $cnt == 2 and $month == 7 { $fh2.print(@year[9]); }
- #cases for month 8
- elsif $cnt == 0 and $month == 8 { $fh2.print(@year[8] ~";"); } elsif $cnt == 1 and $month == 8 { $fh2.print(@year[9] ~";"); }
- elsif $cnt == 2 and $month == 8 { $fh2.print(@year[10]);}
- #cases for month 9
- elsif $cnt == 0 and $month == 9 { $fh2.print(@year[9] ~";"); } elsif $cnt == 1 and $month == 9 { $fh2.print(@year[10]~";"); }
- elsif $cnt == 2 and $month == 9 { $fh2.print(@year[11]);}
- #cases for month 10
- elsif $cnt == 0 and $month == 10 { $fh2.print(@year[10]~";"); } elsif $cnt == 1 and $month == 10 { $fh2.print(@year[11]~";"); }
- elsif $cnt == 2 and $month == 10 { $fh2.print(@year[0]); }
- #cases for month 11
- elsif $cnt == 0 and $month == 11 { $fh2.print(@year[11]~";"); } elsif $cnt == 1 and $month == 11 { $fh2.print(@year[0] ~";"); }
- elsif $cnt == 2 and $month == 11 { $fh2.print(@year[1]); }
- #cases for month 12
- elsif $cnt == 0 and $month == 12 { $fh2.print(@year[0] ~";"); } elsif $cnt == 1 and $month == 12 { $fh2.print(@year[1] ~";"); }
- elsif $cnt == 2 and $month == 12 { $fh2.print(@year[2]); }
- }
- my $app = GTK::Simple::App.new( title => "Tabelas JAS/MAS" );
- $app.set-content(
- GTK::Simple::VBox.new(
- my $label1 = GTK::Simple::Label.new(:text("Informe o arquivo PDF")),
- my $file-chooser-button = GTK::Simple::FileChooserButton.new(:title("Please Select a File"))
- )
- );
- $file-chooser-button.file-set.tap: {
- my $read_file = $file-chooser-button.file-name;
- my $result = (run 'pdftotext', $read_file) or (run 'pdftotext.exe', $read_file);
- if $result {
- #removes present file extension
- $read_file = chop $read_file, 4;
- #Open the txt generated by the pdf file
- my $fh1 = open $read_file~".txt";
- #Writes an csv filled with the txt file
- my $fh2 = open $read_file~".csv", :w;
- #date of creation
- $fh2.say(Date.today.day~"/"~Date.today.month~"/"~Date.today.year);
- my $month = Date.today.month;
- my $day-of-week = Date.today.day-of-week;
- #discover the day of the week and returns the next sunday of the current month
- my $day = Date.today.day;
- given Date.today.day-of-week {
- when 1 { $day += 6; }; when 2 { $day += 5; }
- when 3 { $day += 4; }; when 4 { $day += 3; }
- when 5 { $day += 2; }; when 6 { $day += 1; }
- }
- #discover the amount of weeks per month for the next three months
- my $count;
- my @tmp_day = ();
- for 0..3 -> $_ {
- while $day < Date.today.days-in-month {
- $day += 7;
- $count++;
- if $_ > 0 { @tmp_day.append($day); }
- }
- #the first sunday of the next month
- $day -= Date.today.days-in-month;
- @tmp_day.append($day);
- if $_ > 0 { for ^$count { $fh2.print("; "~@tmp_day[$_]); } ; @month.append: $count; for ^($count+1) { @tmp_day.shift; } }
- $count = 0;
- }
- #break a line
- $fh2.say();
- #first column of 2nd line is name
- $fh2.print("Nomes; ");
- my $i = 0;
- #$count = 0;
- while @month[$i] {
- for ^@month[$i] -> $j {
- if $j != (@month[$i]-1) { $fh2.print(";"); }else { monthName($month, $i, $fh2); }
- }
- $i++;
- }
- #break a line
- $fh2.say();
- #fill in data to the table
- for $fh1.lines -> $line {
- if $line ~~ /\w*\,\w*/ {
- $fh2.say($line);
- }
- }
- #remove txt file
- unlink $read_file~".txt" or die;
- #close handlers
- $fh2.close; $fh1.close;
- $app.exit;
- }
- }
- $app.border-width = 20;
- $app.run;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement