2021 카카오 신입공채 2차 온라인 코딩 테스트 for Tech developers 문제해설
import json
import requests
baseURL/locations
을 get
def locations_api(auth_key):
headers = {'Authorization': auth_key, 'Content-Type': 'application/json'}
url = baseURL + '/locations'
response = requests.get(url, headers = headers)
return response.json()['locations']
baseURL/start
에 post
baseURL =
token =
problem = 1
def start_api():
headers = {'X-Auth-Token': token, 'Content-Type': 'application/json'}
data = f'{{"problem": {problem}}}'
url = baseURL + '/start'
response = requests.post(url, headers = headers, data = data)
if response.status_code == 200:
auth_key = response.json()['auth_key']
else:
auth_key = "failed to get auth key"
return auth_key
baseURL/simulate
에 putdef simulate_api(auth_key, simulations):
headers = {'Authorization': auth_key, 'Content-Type': 'application/json'}
url = baseURL + '/simulate'
data = {'commands': simulations}
response = requests.put(url, headers=headers, data=json.dumps(data))
parsed = response.json()
return parsed
data = {'problem': problem}
response = requests.put(url, headers=headers, data=json.dumps(data))
data = f'{{"problem": {problem}}}'
response = requests.post(url, headers = headers, data = data)