SAFESPACE22 / ParkingSWE

0 stars 0 forks source link

Ingrate api to frontend #29

Open Chimp56 opened 2 months ago

Chimp56 commented 2 months ago

Sample Input and output

Image

Post request in swift:

let parameters = "\r\n{\r\n    \"lot_id\": 2,\r\n    \"floor\": 1,\r\n    \"day_of_week\": 2,\r\n    \"year\": 2020,\r\n    \"month\": 3,\r\n    \"day\": 1,\r\n    \"hour\": 14,\r\n    \"minute\": 30,\r\n    \"second\": 0,\r\n    \"reported_vacant_spots\": 50,\r\n    \"floor_total_spots\": 400,\r\n    \"floor_type\": 2,\r\n    \"temperature\": 20.5,\r\n    \"precipitation\": 0.0,\r\n    \"wind_speed\": 0.0,\r\n    \"is_game_day\": 0,\r\n    \"holiday\": 0\r\n}"
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "http://10.204.146.9:5000/getPredictionOutput")!,timeoutInterval: Double.infinity)
request.addValue("application/json, application/rdap+json", forHTTPHeaderField: "Accept")
request.addValue("en-US,en;q=0.8", forHTTPHeaderField: "Accept-Language")
request.addValue("keep-alive", forHTTPHeaderField: "Connection")
request.addValue("1", forHTTPHeaderField: "DNT")
request.addValue("https://lookup.icann.org", forHTTPHeaderField: "Origin")
request.addValue("https://lookup.icann.org/", forHTTPHeaderField: "Referer")
request.addValue("empty", forHTTPHeaderField: "Sec-Fetch-Dest")
request.addValue("cors", forHTTPHeaderField: "Sec-Fetch-Mode")
request.addValue("cross-site", forHTTPHeaderField: "Sec-Fetch-Site")
request.addValue("1", forHTTPHeaderField: "Sec-GPC")
request.addValue("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36", forHTTPHeaderField: "User-Agent")
request.addValue("\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Brave\";v=\"122\"", forHTTPHeaderField: "sec-ch-ua")
request.addValue("?0", forHTTPHeaderField: "sec-ch-ua-mobile")
request.addValue("\"Windows\"", forHTTPHeaderField: "sec-ch-ua-platform")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")

request.httpMethod = "POST"
request.httpBody = postData

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
  guard let data = data else {
    print(String(describing: error))
    return
  }
  print(String(data: data, encoding: .utf8)!)
}

task.resume()

I can host the api to network to the exact url will change. Parameters is the object sent in the post request.

Chimp56 commented 2 months ago

On execution of 'python parkfindr.py':

Chimp56 commented 2 months ago

I have define the address as: 10.204.146.9

Chimp56 commented 2 months ago

I will be running the dev server during the demo