-1

I'm looking to create a program (right now just trying to see how far I can take it) that is able to retrieve nyc 311 department of building complaints. I did find the api documentation online and I was able to search per complaint number, as far as my program is concerned that defeats the purpose I want to to be able to search by address to see if there is an active complaint so therefore someone wouldn't know there complaint number if they haven't been notified of it. Here is an example of to search with the complaint number; which works.

comNum = "4830407"
response = requests.get('https://data.cityofnewyork.us/resource/eabe-havv.json?complaint_number=%s' %(comNum))

Ok so on the api documentation there are options for zip_code= , house_number= , and house_street= ,

When I attempt to add these to the url like in this example:

responseAddress = requests.get('https://data.cityofnewyork.us/resource/eabe-havv.json?zip_code=11103&house_number=123&house_street=50street' 

nothing returns if I eliminate lets say zip and house_number in printed back an empty sting like so : []

I want to be able to have this program searchable by address but I can't seem to get the url to function the way I'm trying to. You can’t possible search an address by only zip or only house number.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
AnthonyD
  • 1
  • 1

1 Answers1

1

If you look at the raw data (no parameters), looking specifically at zipcodes, there are spaces in it. You'll need to url encode those spaces.

This returns []: https://data.cityofnewyork.us/resource/eabe-havv.json?zip_code=11103

This does not. https://data.cityofnewyork.us/resource/eabe-havv.json?zip_code=11103%20%20%20%20

Looks like house numbers are always 12 characters long, so you could do something like this to get a left-padded string

>>> "{:<12d}".format(113)
'113         '

Related: How to urlencode a querystring in Python?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245