Skip to content

Instantly share code, notes, and snippets.

@hakasenyang
Last active June 28, 2017 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakasenyang/7ef7c21033a2f5d50e9c1316d3ebb992 to your computer and use it in GitHub Desktop.
Save hakasenyang/7ef7c21033a2f5d50e9c1316d3ebb992 to your computer and use it in GitHub Desktop.
카카오톡 오픈채팅 유저 대화내용으로 얼마나 대화했는지 확인할 수 있습니다. (PC버전에서 텍스트 파일로 내보내기 기능을 이용하세요.)
<?php
define('MAX_LEN', (1024*1024*5.5));
function rank( $array ) {
// https://stackoverflow.com/questions/21521986/how-do-i-rank-array-values-with-duplicate-values-without-skipping-any-rank
// initialize variables
$position_array = array();
$copy_array = array();
$final_array = array();
$pos = 1;
// reverse the array
rsort( $array );
// create copy to use on foreach
$copy_array = $array;
// iterate to generate ranking array
foreach ( $copy_array as $claves => $valores ) {
$position_array[] = $pos;
unset( $copy_array[$claves] );
if ( (bool)array_search( $valores, $copy_array, true ) !== false ) {
$pos2++;
} else {
if($pos2) { $pos += $pos2; unset($pos2); }
$pos++;
}
}
unset ( $claves, $valores );
// create an array with values an position
//$final_array['data'] = $array;
$final_array['ranking'] = $position_array;
// clean up
unset( $position_array, $copy_array );
return $final_array;
}
$a = $_POST['aa'];
$ab = $_FILES['ab'];
$chkpc = $_POST['chkpc'];
if(!isset($a) && !isset($ab))
{
abcd:
?>
<p>카카오톡 채팅방 활동량 조회 도구
<br>Made by <a href="//hakase.kr" target="_blank">Hakase</a></p>
<form method="post" enctype="multipart/form-data">
<textarea name="aa" rows="10" cols="50">[하카세] [오후 11:11] 로리</textarea><br>
<input name="ab" id="ab" type="file" /><br>
<input type="radio" name="chkpc" id="pc" value="pc" checked><label for="pc">PC</label>
<input type="radio" name="chkpc" id="ios" value="ios"><label for="ios">Mobile (iOS)</label>
<input type="submit">
</form>
<?php if($err) echo '<p><strong>오류! - '.$err.'</strong></p>'; ?>
<p>사용법
<br>1. PC버전에서 채팅 내보내기 한다.
<br>2. 대화내용을 그대로 여기에 붙여넣는다.
<br>2-1. 파일을 그대로 선택한다.
<br>---- 파일이 선택되어 있으면 파일 우선으로 봄.
<br>3. 버튼 누르면 알아서 계산해줌.
</p>
<p>디자인이 똥인 이유는 <strong>디자인을 못 하기 때문</strong></p>
<p>현재 모바일 데이터는 준비중임. iPhone 에서 내보내기를 통해 테스트 일부 완료.</p>
<p><a href="//gist.github.com/hakasenyang/7ef7c21033a2f5d50e9c1316d3ebb992" target="_blank">View source from github</a></p>
<?php
exit;
}
if($ab['size'])
{
if($ab['size'] > MAX_LEN) {$err=(MAX_LEN / 1024 / 1024).'MB 를 초과함';goto abcd;}
$fp = fopen($ab['tmp_name'], 'r');
$a = fread($fp, $ab['size']);
fclose($fp);
}
else
if(strlen($a) > MAX_LEN) {$err=(MAX_LEN / 1024 / 1024).'MB 를 초과함';goto abcd;}
$a = explode("\r", $a);
if($chkpc == 'ios')
{
$pattern = '/(?:[0-9]{4})\.\ (?:1[0-2]|[0-9])\.\ (?:3[0-1]|2[0-9]|1[0-9]|[0-9])\.\ (?:오전|오후)\ (?:1[0-2]|[0-9])\:(?:[0-9]{2})\,\ (.*)\ \:\ (.*)/U';
$mobile = true;
$chk = preg_match('/([0-9]{4})년 (1[0-2]|[0-9])월 (3[0-1]|2[0-9]|1[0-9]|[0-9])일 (.*){1}요일/U', $a[5], $ymd);
}
else
{
$pattern = '/\[(.*)\]\ \[(오전|오후)\ ([0-9]|[10][0-2])\:([0-5][0-9])\]\ (.*)/U';
$chk = preg_match('/(?:-{15})\ ([0-9]{4})년\ (1[0-2]|[0-9])월\ (3[0-1]|2[0-9]|1[0-9]|[0-9])일\ (.*){1}요일\ (?:-{15})/U', $a[3], $ymd);
$chk2 = preg_match('/(.*)\ 님과\ 카카오톡\ 대화/U', $a[0], $room);
}
$count = count($a);
for($i=0;$i<$count;$i++)
{
$b = preg_match($pattern, $a[$i], $c);
if($c[1]) { $count2++; $u[$c[1]]++; }
}
if(!isset($u)) {$err='데이터를 읽을 수 없음 (호환되지 않음)';goto abcd;}
arsort($u);
$u2 = rank($u);
if ($chk)
echo '<p>'.$ymd[1].'년 '.$ymd[2].'월 '.$ymd[3]. '일 대화부터 측정';
else
echo '<p>기준 날짜(처음 대화한 날)를 알 수 없음';
if ($chk2)
echo '<br>방 이름 : '.$room[1];
else
echo '<br>방 이름 : 알 수 없음';
echo '<br>전체 대화: '.$count2.'개 (LINE: '.$count.')</p><p>';
$i=0;
foreach ($u as $key => $val) {
$val2 = round(($val / $count2) * 100,2);
echo $u2['ranking'][$i].'위 '.$key.'('.$val.')('.$val2.'%)<br>';
$i++;
}
echo '</p>';
?>
@hakasenyang
Copy link
Author

정규식알못입니다. 알아서 소스 최적화하세요. (...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment