old_contents: from flask import request, make_response
  from . import main
  from datetime import datetime, timedelta
  import twilio.twiml
  # import json
  
  
  @main.route("/report_incident", methods=['GET', 'POST'])
  def handle_message():
      message = str(request.values.get('Body'))  # noqa
      twiml = twilio.twiml.Response()
      step = int(request.cookies.get('messagecount', 0))
      # incident_report = json.loads(request.cookies.get('report', "{}"))
      if step is 0 and "report" in message.lower():
          twiml.message("Which Agency Owns the Vehicle? A)SEPTA Bus, B)SEPTA CCT, C)SEPTA, D)PWD, E)PECO, F)Streets, G)Others")  # noqa
      elif step is 1:
          # incident_report["agency"] = "SEPTOR"
          twiml.message("What is the License Plate Number? (eg.MG-1234E)")
      elif step is 2:
          # incident_report["licensePlate"] = "TRAP"
          twiml.message("What is the Vehicle ID? (eg.105014)")
      elif step is 3:
          # incident_report["ID"] = "COOKOOFORCOCOAPUFFS"
          twiml.message("How many minutes has it been Idling for? (eg. 10)")
      elif step is 4:
          twiml.message("Please describe the situation (eg. The driver is sleeping)")  # noqa
      else:
          twiml.message("Thanks!")
          step = -1
      step += 1
      expires = datetime.utcnow() + timedelta(hours=4)
      expires_str = expires.strftime('%a, %d %b %Y %H:%M:%S GMT')
      response = make_response(str(twiml))
      response.set_cookie('messagecount', value=str(step), expires=expires_str)
      # response.set_cookie('report', value=json.dumps(incident_report), expires=expires_str)  # noqa
      return response
  
new_contents: from flask import request, make_response
  from . import main
  from ..models import Agency
  from datetime import datetime, timedelta
  import twilio.twiml
  # import json
  
  
  @main.route("/report_incident", methods=['GET', 'POST'])
  def handle_message():
      message = str(request.values.get('Body'))  # noqa
      twiml = twilio.twiml.Response()
  
      # Retrieve incident cookies
      step = int(request.cookies.get('messagecount', 0))
      vehicle_id = int(request.cookies.get('vehicle_id', 0))
      agency_id = int(request.cookies.get('agency_id', 0))
      license_plate = str(request.cookies.get('license_plate', ""))
      duration = int(request.cookies.get('duration', 0))
      description = str(request.cookies.get('description'))
      body = request.values.get('Body')
  
      if step is 0 and "report" in message.lower():
          twiml.message("Which Agency Owns the Vehicle? A)SEPTA Bus, B)SEPTA CCT, C)SEPTA, D)PWD, E)PECO, F)Streets, G)Others")  # noqa
          agency_name = agency_letter_to_name(body)
          agency_id = Agency.query.filter_by(name=agency_name).first()
      elif step is 1:
          twiml.message("What is the License Plate Number? (eg.MG-1234E)")
          license_plate = body
      elif step is 2:
          twiml.message("What is the Vehicle ID? (eg.105014)")
          vehicle_id = int(body)
      elif step is 3:
          twiml.message("How many minutes has it been Idling for? (eg. 10)")
          duration = int(body)
      elif step is 4:
          twiml.message("Please describe the situation (eg. The driver is sleeping)")  # noqa
          description = body
      else:
          print(vehicle_id)
          print(agency_id)
          print(license_plate)
          print(duration)
          print(description)
          twiml.message("Thanks!")
          step = -1
      step += 1
      response = make_response(str(twiml))
      set_cookie(response, 'messagecount', str(step))
      set_cookie(response, 'agency_id', str(agency_id))
      set_cookie(response, 'vehicle_id', str(vehicle_id))
      set_cookie(response, 'license_plate', license_plate)
      set_cookie(response, 'duration', str(duration))
      set_cookie(response, 'description', description)
      return response
  
  
  def set_cookie(resp, key, val):
      expires = datetime.utcnow() + timedelta(hours=4)
      expires_str = expires.strftime('%a, %d %b %Y %H:%M:%S GMT')
      resp.set_cookie(key, value=val, expires=expires_str)
  
  
  def agency_letter_to_name(letter):
      if letter is 'A':
          return "SEPTA Bus"
      elif letter is 'B':
          return "SEPTA CCT"
      elif letter is 'C':
          return "SEPTA"
      elif letter is 'D':
          return "PWD"
      elif letter is 'E':
          return "PECO"
      elif letter is 'F':
          return "Streets"
      else:
          return "TESTESTESTESTESTESTESt"
  
subject: Add cookie storing for incident report data