Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. use v6;
  2. use GTK::Simple;
  3. use GTK::Simple::App;
  4. use GTK::Simple::FileChooserButton;
  5.  
  6. my @year = ("Janeiro","Fevereiro","Mar�o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro");
  7. my @month = ();
  8.  
  9. sub monthName($month, $cnt, $fh2) {
  10. #cases for month 1
  11. if $cnt == 0 and $month == 1 { $fh2.print(@year[1] ~";"); } elsif $cnt == 1 and $month == 1 { $fh2.print(@year[2] ~";"); }
  12. elsif $cnt == 2 and $month == 1 { $fh2.print(@year[3]); }
  13. #cases for month 2
  14. elsif $cnt == 0 and $month == 2 { $fh2.print(@year[2] ~";"); } elsif $cnt == 1 and $month == 2 { $fh2.print(@year[3] ~";"); }
  15. elsif $cnt == 2 and $month == 2 { $fh2.print(@year[4]); }
  16. #cases for month 3
  17. elsif $cnt == 0 and $month == 3 { $fh2.print(@year[3] ~";"); } elsif $cnt == 1 and $month == 3 { $fh2.print(@year[4] ~";"); }
  18. elsif $cnt == 2 and $month == 3 { $fh2.print(@year[5]); }
  19. #cases for month 4
  20. elsif $cnt == 0 and $month == 4 { $fh2.print(@year[4] ~";"); } elsif $cnt == 1 and $month == 4 { $fh2.print(@year[5] ~";"); }
  21. elsif $cnt == 2 and $month == 4 { $fh2.print(@year[6]); }
  22. #cases for month 5
  23. elsif $cnt == 0 and $month == 5 { $fh2.print(@year[5] ~";"); } elsif $cnt == 1 and $month == 5 { $fh2.print(@year[6] ~";"); }
  24. elsif $cnt == 2 and $month == 5 { $fh2.print(@year[7]); }
  25. #cases for month 6
  26. elsif $cnt == 0 and $month == 6 { $fh2.print(@year[6] ~";"); } elsif $cnt == 1 and $month == 6 { $fh2.print(@year[7] ~";"); }
  27. elsif $cnt == 2 and $month == 6 { $fh2.print(@year[8]); }
  28. #cases for month 7
  29. elsif $cnt == 0 and $month == 7 { $fh2.print(@year[7] ~";"); } elsif $cnt == 1 and $month == 7 { $fh2.print(@year[8] ~";"); }
  30. elsif $cnt == 2 and $month == 7 { $fh2.print(@year[9]); }
  31. #cases for month 8
  32. elsif $cnt == 0 and $month == 8 { $fh2.print(@year[8] ~";"); } elsif $cnt == 1 and $month == 8 { $fh2.print(@year[9] ~";"); }
  33. elsif $cnt == 2 and $month == 8 { $fh2.print(@year[10]);}
  34. #cases for month 9
  35. elsif $cnt == 0 and $month == 9 { $fh2.print(@year[9] ~";"); } elsif $cnt == 1 and $month == 9 { $fh2.print(@year[10]~";"); }
  36. elsif $cnt == 2 and $month == 9 { $fh2.print(@year[11]);}
  37. #cases for month 10
  38. elsif $cnt == 0 and $month == 10 { $fh2.print(@year[10]~";"); } elsif $cnt == 1 and $month == 10 { $fh2.print(@year[11]~";"); }
  39. elsif $cnt == 2 and $month == 10 { $fh2.print(@year[0]); }
  40. #cases for month 11
  41. elsif $cnt == 0 and $month == 11 { $fh2.print(@year[11]~";"); } elsif $cnt == 1 and $month == 11 { $fh2.print(@year[0] ~";"); }
  42. elsif $cnt == 2 and $month == 11 { $fh2.print(@year[1]); }
  43. #cases for month 12
  44. elsif $cnt == 0 and $month == 12 { $fh2.print(@year[0] ~";"); } elsif $cnt == 1 and $month == 12 { $fh2.print(@year[1] ~";"); }
  45. elsif $cnt == 2 and $month == 12 { $fh2.print(@year[2]); }
  46. }
  47.  
  48. my $app = GTK::Simple::App.new( title => "Tabelas JAS/MAS" );
  49.  
  50. $app.set-content(
  51. GTK::Simple::VBox.new(
  52. my $label1 = GTK::Simple::Label.new(:text("Informe o arquivo PDF")),
  53. my $file-chooser-button = GTK::Simple::FileChooserButton.new(:title("Please Select a File"))
  54. )
  55. );
  56.  
  57. $file-chooser-button.file-set.tap: {
  58. my $read_file = $file-chooser-button.file-name;
  59. my $result = (run 'pdftotext', $read_file) or (run 'pdftotext.exe', $read_file);
  60. if $result {
  61. #removes present file extension
  62. $read_file = chop $read_file, 4;
  63. #Open the txt generated by the pdf file
  64. my $fh1 = open $read_file~".txt";
  65. #Writes an csv filled with the txt file
  66. my $fh2 = open $read_file~".csv", :w;
  67.  
  68. #date of creation
  69. $fh2.say(Date.today.day~"/"~Date.today.month~"/"~Date.today.year);
  70.  
  71. my $month = Date.today.month;
  72. my $day-of-week = Date.today.day-of-week;
  73.  
  74. #discover the day of the week and returns the next sunday of the current month
  75. my $day = Date.today.day;
  76. given Date.today.day-of-week {
  77. when 1 { $day += 6; }; when 2 { $day += 5; }
  78. when 3 { $day += 4; }; when 4 { $day += 3; }
  79. when 5 { $day += 2; }; when 6 { $day += 1; }
  80. }
  81. #discover the amount of weeks per month for the next three months
  82. my $count;
  83. my @tmp_day = ();
  84. for 0..3 -> $_ {
  85. while $day < Date.today.days-in-month {
  86. $day += 7;
  87. $count++;
  88. if $_ > 0 { @tmp_day.append($day); }
  89. }
  90. #the first sunday of the next month
  91. $day -= Date.today.days-in-month;
  92. @tmp_day.append($day);
  93. if $_ > 0 { for ^$count { $fh2.print("; "~@tmp_day[$_]); } ; @month.append: $count; for ^($count+1) { @tmp_day.shift; } }
  94. $count = 0;
  95. }
  96. #break a line
  97. $fh2.say();
  98. #first column of 2nd line is name
  99. $fh2.print("Nomes; ");
  100.  
  101. my $i = 0;
  102. #$count = 0;
  103. while @month[$i] {
  104. for ^@month[$i] -> $j {
  105. if $j != (@month[$i]-1) { $fh2.print(";"); }else { monthName($month, $i, $fh2); }
  106. }
  107. $i++;
  108. }
  109. #break a line
  110. $fh2.say();
  111.  
  112. #fill in data to the table
  113. for $fh1.lines -> $line {
  114. if $line ~~ /\w*\,\w*/ {
  115. $fh2.say($line);
  116. }
  117. }
  118. #remove txt file
  119. unlink $read_file~".txt" or die;
  120.  
  121. #close handlers
  122. $fh2.close; $fh1.close;
  123.  
  124. $app.exit;
  125. }
  126. }
  127.  
  128. $app.border-width = 20;
  129. $app.run;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement