Advertisement
riking

!steamcalcbase

Aug 15th, 2014
1,783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.81 KB | None | 0 0
  1. <php,map=steamid>define('_A','ranks');define('_B','rankst');define('_C','//table[@id="table-apps"]/tbody');define('_D','data-sort');ob_start(function($_){return trim($_);});function cmptime($a,$b){return$a[2]<$b[2];}function cmpvalue($a,$b){$_=1000000;$c=1000000;if(($a[2]!==0)&&($a[3]!==0)){$_=$a[3]/$a[2];}else if($a[2]===0){$_+=$a[3];}if(($b[2]!==0)&&($b[3]!==0)){$c=$b[3]/$b[2];}else if($b[2]===0){$c+=$b[3];}return$_>$c;}function cmpvalue2($a,$b){$_=-1000000;$c=-1000000;if(($a[2]!==0)&&($a[3]!==0)){$_=$a[3]/$a[2];}else if($a[2]===0){$_+=$a[3];}if(($b[2]!==0)&&($b[3]!==0)){$c=$b[3]/$b[2];}else if($b[2]===0){$c+=$b[3];}return$_<$c;}function cmpwasted($a,$b){return$a[3]<$b[3];}function cmpstrmoney($a,$b){return floatval(substr($a,1))*100<floatval(substr($b,1))*100;}function cmpint($a,$b){return$a<$b;}function money($d,$e,$f){if($e===0)return'Free';if($f===0)return'N/A';$g='*';$h='%1$s%2$.2f';switch($d){case'au':case'us':$g='$';break;case'de':case'no':$g='€';$h='%2$.2f%1$s';break;case'uk':$g='£';break;case'ru':$g='р.';$h='%2$.2f%1$s';break;case'br':$g='R$';break;}return sprintf($h,$g,($e/100)/($f/60));}function todiff($i){$j=new DateTime();$k=new DateTime();$k->add(new DateInterval('PT'.$i));$l=$k->diff($j);$m=[];if($l->days>0)$m[]=sprintf('%dd',$l->days);if($l->h>0)$m[]=sprintf('%dh',$l->h);if($l->i>0)$m[]=sprintf('%dm',$l->i);if(count($m)==0)return'N/A';return implode(' ',$m);}function loadstate(){global $n,$_STATE;$n=json_decode(json_encode($_STATE),true);if(!isset($n)||$n==[]||gettype($n)!=='array')$n=[_A=>[],_B=>[]];return$n;}try{if($argc===1||$argc===2){$o=strtolower($sender);$p=$argc===2?strtolower($arg[1]):$o;switch(strtolower($arg[0])){case'ranking':printf('Ranking: ');$n=loadstate();uasort($n[_A],'cmpstrmoney');foreach($n[_A]as$q=>$r){printf("\$odd(%s): %s\n",$q,$r);}break;case'rankingtime':printf('Ranking (time): ');$n=loadstate();uasort($n[_B],'cmpint');foreach($n[_B]as$q=>$r){$s=(int)$r;$t=(int)(($r-$s)*60);printf("\$odd(%s): %s\n",$q,todiff($s.'H'.$t.'M'));}break;case'dump':$n=loadstate();echo json_encode($n);break;}throw new Exception('');}else if($argc<4){throw new Exception('usage: <type[time|value|value2|wasted|list|ids|roulette]> <region[us|de|no|uk|ru|br|au]> <gamelimit> <name> OR <type[ranking|rankingtime]> <id[?]>');}$u=$arg[0];$d=$arg[1];$v=(int)$arg[2];$w=implode(' ',array_splice($arg,3));$x=strtolower($w);$n=loadstate();if(isset($map)){$map=array_change_key_case($map);if(array_key_exists($x,$map)){$x=strtolower($map[$x]);}}$y=Requests::get('http://steamdb.info/calculator/?'.http_build_query(['currency'=>$d,'player'=>$x]),[],['timeout'=>10]);if($y->status_code!==200)throw new Exception('failed steamdb.info');$z=$y->body;$A='';try{$y=Requests::get('http://steamcommunity.com/id/'.urlencode($x).'/badges/',[],['timeout'=>5]);if($y->status_code===200){$A=$y->body;if(preg_match('#<h3>The specified profile could not be found.</h3>#',$A)!==false){$y=Requests::get('http://steamcommunity.com/profiles/'.urlencode($x).'/badges/',[],['timeout'=>5]);if(count($y->history)>0){if(preg_match('#http://steamcommunity.com/id/(.*?)/badges/?#',$y->history[0]->headers->offsetGet("location"),$B)){unset($n[_A][$x]);unset($n[_B][$x]);$x=$B[1];}$A=$y->body;}}}}catch(Exception $C){}if(preg_match('#Failed to resolve CustomURL#',$z,$D))throw new Exception($x.': does not exist');if(preg_match('#This profile is private#',$z,$D))throw new Exception($x.': profile is private');if(preg_match('#Failed to receive player\'s games#',$z,$D))throw new Exception($x.': failed to recieve game list');$E=preg_match('#has not purchased any games on Steam#',$z,$D)===1;$F=new DOMDocument();@$F->loadHTML($z);$G=new DOMXPath($F);if(strtolower($u)=='ids'){$H=[];$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr/td[1]');foreach($I as$K){$H[]=intval($K->textContent);}}die(json_encode($H));}else if(strtolower($u)=='roulette'){$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr/td[3]');if($I->length!==0){$L=rand()%$I->length;printf('%s: %s [%d/%d]',$w,$I->item($L)->textContent,$L,$I->length);die();}}die($w.' has no games :(');}$I=$G->query('//h1[contains(@class,"header-title")]/a[contains(@href,"profiles")]');if($I->length===1){printf("%s: ",$I->item(0)->textContent);if($E)printf("doesn't own any games\n");$I=$G->query('//span[contains(concat(" ", normalize-space(@class), " "), " calculator-price ")]');if($I->length===1){$M='';$N=$G->query('//span[contains(@class,"calculator-price-lowest")]');if($N->length===1){$M=sprintf(' (%s)',$N->item(0)->textContent);}printf("%s%s\n",$I->item(0)->textContent,$M);$O=str_replace(',','.',$I->item(0)->textContent);if($O[0]==='$'){$n[_A][$x]=$O;uasort($n[_A],'cmpstrmoney');$P=array_chunk($n[_A],10,true);$n[_A]=$P[0];$_STATE=$n;}}else if(!$E)printf("failed cost\n");$I=$G->query('//tr[contains(td/text(),"Status")]/td[2]');if($I->length===1)printf("%s\n",$I->item(0)->textContent);else{printf("failed status\n");$Q=-1;}if(strlen($A)>0){$R=new DOMDocument();@$R->loadHTML($A);$S=new DOMXPath($R);$I=$S->query('//div/span[@class="profile_xp_block_level"]/span/span');if($I->length===1){printf("Level: %d",$I->item(0)->textContent);$I=$S->query('//div/span[@class="profile_xp_block_xp"]');if($I->length===1)$T=preg_replace('#[^\d]#','',$I->item(0)->textContent);else$T=-1;$I=$S->query('//div/div[@class="profile_xp_block_remaining"]');if($I->length===1)$U=preg_replace('#(Level \d+|[^\d])#','',$I->item(0)->textContent);else$U=-1;if($T>0&&$U>0)printf(" (%d/%d)",$T,$T+$U);printf("\n");$I=$S->query('//div[@class="badge_info_unlocked"]');printf("Badges: %d\n",$I->length);}else printf("failed level\n");}$I=$G->query('//tr[contains(td/text(),"Games owned")]/td[2]');$Q=-1;if($I->length===1)$Q=$I->item(0)->textContent;else if(!$E)printf("failed owned\n");$V=0;$H=[];$I=$G->query(_C);if($I->length===1){$J=$I->item(0);$I=$G->query('//table[@id="table-apps"]/tbody/tr');foreach($I as$K){$W=$K->getElementsByTagName('td');$H[]=[$W->item(1)->textContent,$W->item(2)->textContent,(int)$W->item(3)->getAttribute(_D),(int)$W->item(4)->getAttribute(_D)];if((int)$W->item(3)->getAttribute(_D)===0)$V++;}}else if(!$E)printf("failed games\n");if($Q>0)printf("Games played/owned: %d/%d (%.1f%%)\n",$Q-$V,$Q,100*($Q-$V)/$Q);$I=$G->query('//tr[contains(td/text(),"Hours spent")]/td[2]');if($I->length===1){$m=floatval(preg_replace('#h$#','',str_replace(',','',$I->item(0)->textContent)));$n[_B][$x]=$m;uasort($n[_B],'cmpint');$P=array_chunk($n[_B],10,true);$n[_B]=$P[0];$_STATE=$n;$s=(int)$m;$t=(int)(($m-$s)*60);printf("Time spent: %s\n",todiff($s.'H'.$t.'M'));}else if(!$E)printf("failed hours spent\n");$I=$G->query('//tr[contains(td/text(),"Profile creation")]/td[2]/span/@title');if($I->length===1)printf("Profile created: %s\n",date('M j, Y',strtotime($I->item(0)->textContent)));else printf("failed profile creation\n");$I=$G->query('//tr[contains(td/text(),"Last log off")]/td[2]/span/@title');if($I->length===1)printf("Last seen: %s\n",date('M j, Y',strtotime($I->item(0)->textContent)));else printf("failed last seen\n");if(count($H)>0){switch($u){case'time':usort($H,'cmptime');break;case'value':usort($H,'cmpvalue');break;case'value2':usort($H,'cmpvalue2');break;case'wasted':usort($H,'cmpwasted');break;}$j=new DateTime();switch($u){case'time':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){printf("\x02%s\x02: %s\n",trim($H[$L][1]),todiff($H[$L][2].'M'));$X++;}break;case'value':case'value2':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){if($H[$L][3]>0){printf("\x02%s\x02: %s per hour (%s)\n",trim($H[$L][1]),money($d,$H[$L][3],$H[$L][2]),money($d,$H[$L][3],60));$X++;}}break;case'wasted':for($L=0,$X=0;$L<count($H)&&$X<$v;$L++){if($H[$L][2]==0){printf("\x02%s\x02 (%s)\n",trim($H[$L][1]),money($d,$H[$L][3],60));$X++;}}break;case'list':ob_clean();$P=[];for($L=0;$L<count($H);$L++){$P[]=trim($H[$L][1]);}echo json_encode($P);break;}}}else printf("Profile %s doesn't exist.",$x);}catch(Exception $Y){printf('%s',$Y->getMessage());}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement