-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdfScrape.rb
64 lines (42 loc) · 1.61 KB
/
pdfScrape.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'pdf/reader'
output = File.new("output.csv","w")
output.print("ownerName,propertyAddress,taxClass,estimatedValue,assesedValue,taxRate,taxBefore,annualTax\n")
Dir.glob("*.pdf") do |thisPdf| #loop through pdfs in this directory
puts "working on #{thisPdf}..."
reader = PDF::Reader.new(thisPdf)
reader.pages.each do |page|
rawText = page.text
if rawText.include? 'Owner name'
t = rawText.split('Owner name:')[1][0...40].strip!
puts "Owner Name: " + t
output.print('"' + t + '",')
t = rawText.split('Property address:')[1][0...30].strip!
puts "Property Address: " + t
output.print(t + ',')
end
if rawText.include? 'How We'
t = rawText.split('Tax class')[1][0...40].strip!
puts "Tax Class: " + t
output.print('"' + t + '",')
t = rawText.split('Estimated market value')[1][0...40].strip!
t = t.gsub(/\D/, '')
puts "Estimated market value: " + t.to_s()
output.print(t.to_s() + ',')
t = rawText.split('Tax before exemptions and abatements')[1][0...80].strip!
assessedValue = t.split('X')[0].gsub(/\D/, '')
puts "Billable Assessed Value: " + assessedValue
output.print(assessedValue + ',')
taxRate = t.split('X')[1].split('=')[0].strip!
puts "Tax Rate: " + taxRate
output.print(taxRate + ',')
taxBefore = t.split("=")[1].gsub(/\D/, '')
puts "Tax before exemptions and abatements: " + taxBefore
output.print(taxBefore + ',')
t = rawText.split('Annual property tax')[1][0...98].gsub(/\D/, '')
puts "Annual Property Tax: " + t
output.print(t)
end
end
output.print("\n")
puts "" #blank line in terminal after each pdf
end