title: Simplify a streamed request.get and JSON response decode
body: <p>I have been working on some code that will grab emergency incident information from a service called PulsePoint. It works with software built into computer controlled dispatch centers.</p>
  
  <p>This is an app that empowers citizen heroes that are CPR trained to help before a first resonder arrives on scene. I'm merely using it to get other emergency incidents.</p>
  
  <p>I reversed-engineered there app as they have no documentation on how to make your own requests. Because of this <strong>i have knowingly left in the api key and auth info</strong> because its in plain text in the Android manifest file.</p>
  
  <p>I will definitely make a python module eventually for interfacing with this service, for now its just messy.</p>
  
  <p>Anyhow, sorry for that long boring intro.</p>
  
  <p>My real question is, how can i simplify this function so that it looks and runs a bit cleaner in making a timed request and returning a json object that can be used through subscripts?</p>
  
  <pre><code>import requests, time, json
  def getjsonobject(agency):
      startsecond = time.strftime("%S")
      url = REDACTED
      body = []
      currentagency = requests.get(url=url, verify=False, stream=True, auth=requests.auth.HTTPBasicAuth(REDACTED, REDCATED), timeout = 13)
      for chunk in currentagency.iter_content(1024):
          body.append(chunk)
          if(int(startsecond) + 5 &lt; int(time.strftime("%S"))): #Shitty internet proof, with timeout above
              raise Exception("Server sent to much data")
      jsonstringforagency = str(b''.join(body))[2:][:-1] #Removes charecters that define the response body so that the next line doesnt error
      currentagencyjson = json.loads(jsonstringforagency) #Loads response as decodable JSON
      return currentagencyjson
  
  currentincidents = getjsonobject("lafdw")
  for inci in currentincidents["incidents"]["active"]:
      print(inci["FullDisplayAddress"])
  </code></pre>