Skip to content
Browse files

fixed: bug where bot would stop running unless limit was supplied

  • Loading branch information...
1 parent 01d7f88 commit 38621cd7e24bd0fabab5a9ceb483c09345cf5638 @jaredfolkins committed
Showing with 27 additions and 9 deletions.
  1. +4 −3 lib/bot.rb
  2. +20 −4 lib/convert.rb
  3. +3 −2 lib/default_sale.rb
View
7 lib/bot.rb
@@ -24,12 +24,13 @@ def setup_limit
end
def click_next_if_limit_is_not_reached(page)
- puts "Limit: #{@limit} || Limit Count: #{@limit_count}"
- if @limit.to_i == @limit_count.to_i
+ if @limit.to_i >= 1 && @limit.to_i == @limit_count.to_i
+ puts "Limit: #{@limit} || Limit Count: #{@limit_count}"
puts 'Limit Reached Shutting Down!'
exit 1
else
- @limit_count += 1
+ puts "Limit: #{@limit} || Limit Count: #{@limit_count}"
+ @limit_count.to_i += 1 unless @limit_count.nil?
click_next_link(page)
end
end
View
24 lib/convert.rb
@@ -4,10 +4,25 @@ class Convert < Dbconnection
TXT_PATH = CURRENT_DIR + "/../storage/convert/txt/"
TMP_PATH = CURRENT_DIR + "/../storage/convert/tmp/"
FAIL_PATH = CURRENT_DIR + "/../storage/convert/fail/"
- DPI = [150, 300, 450, 600]
+ DPI = [150, 300]
attr_accessor :total_documents, :total_successes
+ def initialize
+ setup_arguments
+ end
+
+ def setup_arguments
+ Choice.options do
+ header 'Deschutes County Records PDF Converter Options:'
+ separator 'Optional:'
+ option :year do
+ long '--year=YEAR'
+ desc 'Only convert documents that begin with a certain year.'
+ end
+ end
+ end
+
def run
@total_documents = 0
@total_successes = 0
@@ -27,7 +42,8 @@ def confirm_single_process
end
def convert!
- Dir.glob("#{CURRENT_DIR}/../storage/pdf/*.pdf") do |path_to_pdf|
+ files = Choice.choices[:year] ? "#{Choice.choices[:year]}*.pdf" : "*.pdf"
+ Dir.glob("#{CURRENT_DIR}/../storage/pdf/#{files}") do |path_to_pdf|
delete_files_from_dirs
volpage = parse_volpage_from_filename(path_to_pdf)
puts "\nVolpage: #{volpage} || Percentage: #{percent_of} || Documents: #{@total_documents} || Successes: #{@total_successes}"
@@ -44,7 +60,7 @@ def conversion_and_parsing_chain(volpage, path_to_pdf)
convert_image_to_txt(volpage)
sale_date = parse_and_get_date_from_file(volpage)
status = sale_date.nil? ? 'Fail ' : 'Success'
- puts "Pass: #{index} || Status: #{status} || File: #{volpage}.pdf || Dpi: #{dpi} || Date: #{sale_date}"
+ puts "\n\tPass: #{index} || Status: #{status} || File: #{volpage}.pdf || Dpi: #{dpi} || Date: #{sale_date}"
break unless sale_date.nil?
end
@@ -60,7 +76,7 @@ def conversion_and_parsing_chain(volpage, path_to_pdf)
def percent_of
percentage = @total_successes.to_f / @total_documents.to_f * 100.0
- percentage.to_s[0..1] + "%"
+ percentage.to_s[0..5] + "%"
end
def move_pdf_to_fail(volpage)
View
5 lib/default_sale.rb
@@ -3,8 +3,9 @@ class DefaultSales < ActiveRecord::Base
def self.parse_date(file)
target = get_target_date_string(file)
unless target.nil?
- puts "Target:"
- target.to_s.each_line { |line| puts "#{line}" }
+ puts "\tTarget:"
+ target.to_s.each_line { |line| puts "\t#{line}" }
+ puts "\n"
end
unless target.nil?
words = get_date_words(target).to_s

0 comments on commit 38621cd

Please sign in to comment.
Something went wrong with that request. Please try again.