Last active
April 17, 2019 08:53
-
-
Save shoark7/23831010a30c0c12071b3d5c225cfd8b to your computer and use it in GitHub Desktop.
It's for Joohyung
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """코드 실행하기 전에 너가 작업하는 환경에서 CMD에(윈도우 쓰지?) | |
| pip3 install requests | |
| 라고 입력해서 이 모듈을 다운 받아. 굉장히 유명하고, urllib 이런거보다 사용성이 훨씬 좋아. | |
| """ | |
| import json | |
| import requests # 모듈명은 abc 순서대로 차례로 적고, | |
| KEY = '너의바로그키키는차열쇠를나타내기도하지' | |
| URL = 'http://tools.kinds.or.kr:8888/issue_ranking' | |
| # 변수와 상수는 확실하게 구분해야함. 키와 url은 상수지. 상수는 변하지 않는 값. 상수는 UPPERCASE | |
| headers = { | |
| 'access_key': KEY, | |
| # access_key는 꼭 있어야 하지만, argument는 네 요구사항에 따라 달라질거야. 이건 예시. | |
| 'argument': { | |
| 'date': '2019-03-30', | |
| 'provider': [] | |
| } | |
| } | |
| response = requests.post(URL, data=json.dumps(headers)) | |
| # response와 headers 사이만 한 줄이 아닌 두 줄을 띄었어. 변수와 기능(함수) 정의와 실행코드는 완전히 분리되는 영역이니까. | |
| # http post request에서는 추가적인 요청 정보를 요청 메시지 헤더에 담을 수 있어. | |
| # 헤더를 이 API에서는 json 형태가 아닌 문자열화해서 보내도록 요구하고 있어서 json.dumps 씀. | |
| data = response.json() # <-- 이게 반환된 값에서 필요한 json data를 추출한 결과. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment