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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/query-nyc.rb', line 13
def self.building_at(houseno, street, boro)
require "nokogiri"
boro_option = name_to_number(boro)
uri = "http://a810-bisweb.nyc.gov/bisweb/PropertyProfileOverviewServlet?" + "boro=#{boro_option}" + "&houseno=#{houseno}" + "&street=#{CGI.escape(street)}"
@page = Nokogiri::HTML(open(uri))
retObj = {:landlords=>[],:building=>[]}
msg = @page.css(".errormsg").first.content rescue nil
if msg == nil
tax_block = @page.xpath("//table[3]/tr[2]/td[9]/text()").to_s.sub(/:/,'').to_i
tax_lot = @page.xpath("//table[3]/tr[3]/td[9]/text()").to_s.sub(/:/,'').to_i
violations_count = @page.xpath("//td//tr[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 2) and parent::*)]/text()").to_s
open_violations = @page.xpath("//td//tr[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]/text()").to_s
violations_link = "http://a810-bisweb.nyc.gov/bisweb/" + @page.xpath("//tr[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]//b//a").attribute("href").to_s rescue ""
complaints_count = @page.xpath("//td//tr[(((count(preceding-sibling::*) + 1) = 2) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 2) and parent::*)]/text()")[0].to_s
open_complaints = @page.xpath("//td//tr[(((count(preceding-sibling::*) + 1) = 2) and parent::*)]//*[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]/text()").to_s
complaints_link = "http://a810-bisweb.nyc.gov/bisweb/" + @page.xpath("//tr[(((count(preceding-sibling::*) + 1) = 2) and parent::*)]//b//a").attribute("href").to_s rescue ""
landmark_status = @page.xpath('//tr[(((count(preceding-sibling::*) + 1) = 6) and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "content", " " )) and (((count(preceding-sibling::*) + 1) = 2) and parent::*)]/text()').to_s
@page = Nokogiri::HTML(open('http://api.blocksandlots.com/blankslate/json/data/743cd788-eb98-4fb6-af18-0811261ad168/records/search?apikey=cvq842zthjdvr25cq9p5s6db&Block='+tax_block.to_s+'&Lot='+tax_lot.to_s+'&rp=350&em=true&_=1289069608577'))
arr_of_landlords = retObj[:landlords]
arr_of_building = retObj[:building]
jdata = JSON.parse(@page.content)
owners_array = jdata["application"][0]["entity"][0]["record"]
owners_array.each do |owner|
ret = {}
skip = false
owner["field"].each { |f|
case f["fieldName"]
when "Owner Name"
if f["fieldValue"].strip.present?
ret[:owner] = f["fieldValue"].split(/\s+/).each{ |word| word.capitalize! }.join(' ')
else
skip = true
end
end
}
arr_of_landlords.push(ret) unless skip
end
r = {}
owners_array[0]["field"].each do |f|
case f["fieldName"]
when "Actual Land Value"; r[:land_value] = f["fieldValue"]
when "Actual Total Value"; r[:total_value] = f["fieldValue"]
when "Market Value"; r[:market_value] = f["fieldValue"]
when "Assessment Year"; r[:assessment_year] = f["fieldValue"]
end
end
arr_of_building.push(r)
arr_of_building[0][:tax_block] = tax_block
arr_of_building[0][:tax_lot] = tax_lot
arr_of_building[0][:violations_count] = violations_count
arr_of_building[0][:open_violations] = open_violations
arr_of_building[0][:violations_link] = violations_link
arr_of_building[0][:complaints_count] = complaints_count
arr_of_building[0][:open_complaints] = open_complaints
arr_of_building[0][:complaints_link] = complaints_link
arr_of_building[0][:landmark_status] = landmark_status.present?
end
retObj
end
|