7월 프로젝트로 진행하였던 배틀그라운드 API를 활용한 사이트(pd.gg)에 웹 기능 구상도
내가 주로 다루었던 페이지는 빨간색으로 표시한 무기 분석 페이지다.
배틀그라운드 개발자 센터 << 개인당 2개의 API Key를 받을 수 있음 (1분당 10회에 요청 제한이 있음)
유저 정보 페이지에서 본인의 무기 숙련도 Top3을 보여줄 때 사용
무기 분석 페이지와 무기 상세 페이지에서 무기 티어와 상성 간 승률을 나타내기 위해 사용
import requests
# 개인 정보 변수
api_key = 'YOUR_PUBG_API_KEY' # 여기에 본인의 PUBG API 키를 입력하세요
player_id = 'YOUR_PLAYER_ID' # 여기에 플레이어 ID를 입력하세요
platform = 'kakao' # 플랫폼 정보 (예: kakao, steam 등)
def get_top3_weapon_mastery(api_key, platform, player_id):
url = f"https://api.pubg.com/shards/{platform}/players/{player_id}/weapon_mastery"
headers = {
"Authorization": API_KEY,
"Accept": "application/vnd.api+json"
}
response = requests.get(url, headers=headers)
# 응답 처리
if response.status_code == 200:
data = response.json()
weapon_mastery = data['data']['attributes']['weaponSummaries']
# 경험치를 기준으로 무기 정렬
sorted_weapons = sorted(weapon_mastery.items(), key=lambda x: x[1]['XPTotal'], reverse=True)
# 상위 3개 무기 출력
top3_weapons = sorted_weapons[:3]
for idx, weapon in enumerate(top3_weapons, start=1):
weapon_name = weapon[0].split('_')[-2] # Split the string to get the weapon name
experience = weapon[1]['XPTotal']
print(f"Top {idx}: {weapon_name} - 경험치: {experience}")
else:
print("API 요청이 실패했습니다. 상태 코드:", response.status_code)
player_id = player_id # 플레이어 ID
api_key = api_key
get_top3_weapon_mastery(api_key, platform, player_id)