dataitgirls4 / team_5

데모데이 5조
https://dataitgirls4.github.io/team_5/
7 stars 5 forks source link

[데이터추출] api로 가져온 데이터를 json으로 바꾸고 저장 #16

Closed haein-kim closed 3 years ago

haein-kim commented 3 years ago

당장 사용하지는 않겠지만 언젠가를 위해서 코드 커밋해두었습니다.

import json
import requests

api_key = "본인 API KEY"

header = {
  "Authorization": api_key,
  "Accept": "application/vnd.api+json"
}

url = "https://api.pubg.com/tournaments/as-pcs3as"

r = requests.get(url, headers=header)
r_data = r.json()
r_data

# dict 형태로 되어있는 데이터를 json 형식으로 바꿔주는 코드
load_data = json.dumps(r_data)

# 'tournaments_pcs3as.json' -> 저장할 파일명 지정
with open('tournaments_pcs3as.json', 'w') as make_file:
    json.dump(load_data, make_file, ensure_ascii=False)

# 작업 중인 이 파일이 있는 폴더에 가면 json 생성
haein-kim commented 3 years ago

https://github.com/dataitgirls4/team_5/blob/main/api-to-json.py

haein-kim commented 3 years ago

telemetry 관련된 걸 하기 전까지는 아마 잠시 사용할 일 없을 거 같네요!