본문 바로가기

IT/mini_project

[part 2] php-riot-api 이용 데이터수집

개발환경셋팅은 끝낫고 데이터가 필요하다.

그때그때 api를 통해 받아내기보다 데이터로 저장하여 써야겠다.

그래서 데이터베이스 db_lol을 만들고 내부 테이블을 하나씩 만들어가며 저장하기 시작했다.

일단 php-riot-api를 클론후 testing.php페이지를 물러오며 가져온 데이터를 db에 insert 시키는 방식으로

진행했다. 그런데 php-riot-api에는 static-data의 챔피언 세부데이터를 가져오는 함수가 없어 새로 만들었다.


getChampData로 함수명을 정하고 로직은

public function getChampData($call, $id=null) {

if($id != ''){

$call = self::API_URL_STATIC_1_2 . "champion/".$id."?champData=".$call;

}else{

$call = self::API_URL_STATIC_1_2 . "champion?champData=".$call;

}


return $this->request($call, true);

}

이런식으로 champData를 먼저 수집하기 시작했다.


static_data_champion 테이블을 생성하고 getStatic('champion');  함수로 불러온 데이터를 foreach돌려 insert 시켯다.

$r = $test->getStatic('champion');

foreach($r['data'] as $champ){

$sql ="

insert static_data_champion 

set id = '".$champ['id']."',

`key` = '".$champ['key']."',

`name` = '".$champ['name']."',

title = '".$champ['title']."'

";


mysql_query($sql);

}

이렇게 챔피언 데이터테이블 완성.


다음으로 챔피언정보 즉 공격력, 마법력 등등 을 가져오는 함수 getChampData('info', $id); 로 챔피언정보를 저장시켰다.

foreach($result as $row){

$r = $test->getChampData('info', $row['id']);

$sql ="insert static_data_champion_info

set id = ".$r['info']['id'].",

defense = ".$r['info']['defense'].",

magic = ".$r['info']['magic'].",

difficulty = ".$r['info']['difficulty'].",

attack = ".$r['info']['attack']."

";

mysql_query($sql);

}


다음은 패시브정보 getChampData('passive', $id); 로 패시브를 저장시켰다.

$sql ="

insert static_data_champion_passive

set id = ".$row['id'].",

sanitizedDescription = '".$r['passive']['sanitizedDescription']."',

description = '".$r['passive']['description']."',

name = '".$r['passive']['name']."',

image_name = '".$r['passive']['image']['full']."'

";

sql문만 남기겟다.


스킨정보

$sql ="

insert static_data_champion_skins

set champ_id = ".$row['id'].",

skin_id = '".$skin['num']."',

name = '".$skin['name']."'

";




'IT > mini_project' 카테고리의 다른 글

[part_1] 라라벨+react 셋팅  (0) 2016.04.27