-
-
Save vk2gpu/4323813 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| set_time_limit(-1); | |
| if(isset($_GET['ld']) and is_numeric($_GET['ld'])) | |
| $TARGETLD = $_GET['ld']; | |
| else | |
| $TARGETLD = 21; | |
| $compolink = "http://ludumdare.com/compo/ludum-dare-$TARGETLD/"; | |
| // connect to database | |
| $dbHost = 'localhost'; | |
| $dbUser = 'ldstats'; | |
| $dbPass = 'ldstats1'; | |
| $dbDatabase = 'ldstats'; | |
| $connection = mysql_connect($dbHost, $dbUser, $dbPass); | |
| @mysql_select_db($dbDatabase) or die("Unable to access database"); | |
| try | |
| { | |
| mysql_query("CREATE TABLE `user` ( | |
| `ld` INT NOT NULL , | |
| `name` VARCHAR( 50 ) NOT NULL , | |
| `entryid` INT NOT NULL , | |
| `votesby` INT NOT NULL , | |
| `votesfor` INT NOT NULL | |
| )"); | |
| mysql_query("CREATE TABLE `entry` ( | |
| `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , | |
| `ld` INT NOT NULL, | |
| `name` VARCHAR( 150 ) NOT NULL , | |
| entrytype VARCHAR(5) DEFAULT 'compo' | |
| )"); | |
| mysql_query("CREATE TABLE `vote` ( | |
| entryid INT NOT NULL, | |
| ld INT, | |
| innovation VARCHAR(1), | |
| fun VARCHAR(1), | |
| theme VARCHAR(1), | |
| graphics VARCHAR(1), | |
| audio VARCHAR(1), | |
| humor VARCHAR(1), | |
| overall VARCHAR(1), | |
| community VARCHAR(1), | |
| category VARCHAR(10) | |
| )"); | |
| } | |
| catch(Exception $e) | |
| {} | |
| $content = file_get_contents($compolink . '?action=misc_links' ); | |
| // find the table contents | |
| $matches = array(); | |
| preg_match( "&<table>([\S\s]*)</table>&", substr($content,250), $matches); | |
| if(count($matches) == 0) | |
| die('Failed to get stats table from page'); | |
| $tablecontent = $matches[1]; | |
| //truncate table for this LD | |
| mysql_query("DELETE FROM user WHERE ld = $TARGETLD"); | |
| mysql_query("DELETE FROM entry WHERE ld = $TARGETLD"); | |
| mysql_query("DELETE FROM vote WHERE ld = $TARGETLD"); | |
| // break into table rows | |
| $rows = preg_split("&<tr>&", $tablecontent); | |
| $counted = 0; | |
| print "Found " . count($rows) . " entries<br/>"; | |
| foreach($rows as $row) | |
| { | |
| // get link to game page | |
| $matches = array(); | |
| preg_match("%<td><a href='(\?action=preview&uid=[0-9]*)'>(.*)</a><td>(.*)<td><a%", $row, $matches); | |
| // line, link, game name, author | |
| if($counted > 4) | |
| exit(); | |
| if( count($matches) > 2) | |
| { | |
| $counted++; | |
| $link = $compolink . $matches[1]; | |
| $entryname = mysql_real_escape_string($matches[2]); | |
| $username = mysql_real_escape_string($matches[3]); | |
| $tds = preg_split("&<td>&", $row); | |
| $count = count($tds); | |
| $votesfor = mysql_real_escape_string($tds[$count-3]); | |
| $votesby = mysql_real_escape_string($tds[$count-2]); | |
| // create entry | |
| mysql_query("INSERT INTO entry (ld, name) VALUES ($TARGETLD, '$entryname')"); | |
| $entryid = mysql_insert_id(); | |
| // create user | |
| mysql_query("INSERT INTO user (ld, name, entryid, votesby, votesfor) VALUES ($TARGETLD, '$username', $entryid, $votesby, $votesfor)"); | |
| #print "$username - $entryname <br/> $votesfor $votesby<hr/>"; | |
| // load entry page | |
| $pagecontent = file_get_contents($link); | |
| // find if Competition Entry or Game Jam Entry | |
| if(strstr($pagecontent, "<i>48 Hour Competition Entry</i>") === False) | |
| mysql_query("UPDATE entry SET entrytype = 'jam' WHERE id = $entryid"); | |
| // find the table contents | |
| $m = array(); | |
| $start = stripos($pagecontent, '<h3>Ratings</h3>'); | |
| $comments = stripos($pagecontent, '<h3>Comments</h3>'); | |
| /* | |
| print "start: $start -- Comments: $comments"; | |
| print "<Pre>"; | |
| print substr($pagecontent, $start, $comments-$start); | |
| print "</pre>";*/ | |
| preg_match( "&<h3>Ratings</h3><p><table cellpadding=5>([\S\s]*)</table>&", substr($pagecontent,$start, $comments-$start), $m); | |
| if(count($m) == 0) | |
| die('Failed to get vote table from page'); | |
| // break into table rows | |
| $votetablecontent = $m[1]; | |
| $voterows = preg_split("&<tr>&", $votetablecontent); | |
| foreach($voterows as $vrow) | |
| { | |
| $vtds = preg_split("&<td align=center>&", $vrow); | |
| if(count($vtds) < 9) | |
| continue; | |
| $inn = mysql_real_escape_string($vtds[1]); | |
| $fun = mysql_real_escape_string($vtds[2]); | |
| $the = mysql_real_escape_string($vtds[3]); | |
| $gra = mysql_real_escape_string($vtds[4]); | |
| $aud = mysql_real_escape_string($vtds[5]); | |
| $hum = mysql_real_escape_string($vtds[6]); | |
| $ove = mysql_real_escape_string($vtds[7]); | |
| $com = mysql_real_escape_string($vtds[8]); | |
| mysql_query("INSERT INTO vote (ld, entryid, innovation, fun, theme, graphics, audio, humor, overall, community) | |
| VALUES ($TARGETLD, $entryid, '$inn', '$fun', '$the', '$gra', '$aud', '$hum', '$ove', '$com')"); | |
| } // end foreach $rows as $row | |
| } // end if count(matches) > 2 | |
| } // end foreach $rows as $row | |
| print "$counted users counted"; | |
| mysql_query("UPDATE vote SET category = innovation | |
| WHERE | |
| innovation = fun | |
| AND theme = fun | |
| AND graphics = fun | |
| AND audio = fun | |
| AND humor = fun | |
| AND overall = fun | |
| AND community = fun"); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ludum Dare entry pulling script. Need to improve this to pull download links and what not too.