Gizmodo eBay Strangeness Score Generator

Well, ask and you shall receive. Kind reader K sent us his homebrew GSS generator written in PHP. It's a fascinating piece of code using high-level algorithms and math to prove that the post length and number of uppercase characters can be used to measure the total insanity of any eBay post. Case in point:

Auction 1 - PLEASE HELP!WHAT'S GROWING ON MY HEAD!! MYSTERY AUCTION GSS Score: 66,731

Auction 2 - EXTRA LARGE HOBO BIG GREEN PURSE BAG RING NEW GSS Score: 1,273

As we see, even if the poster tends to use capital letters, the GSS generator is not fooled.

The GSS Generator is available after the jump for further study. I suspect it might be slightly insecure and therefore would like a few pairs of eyes to ensure that we can indeed host this valuable tool on a server someday, thereby allowing millions of men and women to separate the eBay wheat from the eBay insane people.

Related
eBay Deal of the Day: Vampire Killing Kit

RUN AT YOUR OWN RISK - I'm not going to go through these to make sure they don't "rm -rf" your boot dir.

<?Php
/*
Simple form to grab eBay auction page and calculate Gizmodo Strangeness Score

I take no responsibility for anything done with any of this. Use at your own risk.
More testing is proably needed.

*/

?>
<html>
<head>
<title>GSS Generator Beta</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="gss.php" method="post" name="url_form">
<table width="75%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr>
<td bgcolor="#000000"><font color="#FFFFFF"><strong>Enter URL </strong></font></td>
</tr>
<tr>
<td><input name="url" type="text" size="100"></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?Php

if(isset($_POST['url']) ) {

$url_to_calc = $_POST['url'];

if( $buffer = file_get_contents($url_to_calc) ) {


$begin_string = "<!— Begin Description —>";
$end_string = "<!— End Description —>";

//Find Begin and end auction crap
$beg_pos = strpos($buffer,$begin_string);
$end_pos = strpos($buffer,$end_string,$beg_pos);

//grab just stuff between begin and end auction comments
$desc_text = substr($buffer,($beg_pos + strlen($begin_string)),($end_pos - $beg_pos));

//Strip out the tags then strip out space
$strip_text = strip_tags($desc_text);
$strip_text = str_replace(" ","",$strip_text);
//Strip out line breaks and returns (proabbly don't need to do this)
$strip_text = preg_replace("/(\r\n|\n|\r)/", "", $strip_text);

//find lenght of stripped text
$len_strip_text = strlen($strip_text);


//Counter vars
$num_lower = 0;
$num_upper = 0;
$num_other = 0;

//loop through stripped text count upper, lower and other chars
for($x = 0; $x < $len_strip_text; $x++) {
$test_char = substr($strip_text,$x,1);

$ascii_num = ord($test_char);

if( ($ascii_num >= 97) && ($ascii_num <= 122) ){
$num_lower++;
} else {
if( ($ascii_num >= 65) && ($ascii_num <= 90) ) {
$num_upper++;
} else {
$num_other++;
}
}

}

//Calculate Gizmodo Strangeness Score
$gss = ($len_strip_text - $num_other) * ($num_upper / $num_lower);



echo "<em>URL = $url_to_calc</em>";
?>
<table width="75%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
<tr bgcolor="#000000">
<td colspan="2"><font color="#FFFFFF"><strong>Summary Data:</strong></font></td>
</tr>
<tr>
<td width="33%" bgcolor="#666666"><div align="right"><strong><font color="#FFFFFF" size="-1">Total Chars</font></strong></div></td>
<td width="67%" bgcolor="#CCCCCC"><strong>&nbsp; <?Php echo number_format($len_strip_text); ?></strong></td>
</tr>
<tr>
<td bgcolor="#666666"><div align="right"><strong><font color="#FFFFFF" size="-1">Number uppercase</font></strong></div></td>
<td bgcolor="#CCCCCC"><strong>&nbsp; <?Php echo number_format($num_upper); ?></strong></td>
</tr>
<tr>
<td bgcolor="#666666"><div align="right"><strong><font color="#FFFFFF" size="-1">Number lowercase</font></strong></div></td>
<td bgcolor="#CCCCCC"><strong>&nbsp; <?Php echo number_format($num_lower); ?></strong></td>
</tr>
<tr>
<td bgcolor="#666666"><div align="right"><strong><font color="#FFFFFF" size="-1">Number other chars</font></strong></div></td>
<td bgcolor="#CCCCCC"><strong>&nbsp; <?Php echo number_format($num_other); ?></strong></td>
</tr>
<tr>
<td bgcolor="#666666"><div align="right"><strong><font color="#FFFFFF" size="-1">Gizmodo
Strangeness Score* </font></strong></div></td>
<td bgcolor="#CCCCCC"><strong>&nbsp; <?Php echo number_format($gss,4); ?></strong></td>
</tr>
</table>
<BR><font size="-1"><em>*(Number Chars - Number Other Chars) x (Number Upper / Number Lower)</em></font><BR><BR>


<?Php
echo "<BR>Stripped Text (blank space removed): <BR>";
echo $strip_text;

} else {
echo "ERROR fetching file";
}

}

?>
</body>
</html>

Here is an interesting command-line version in Perl by Thomas:

#!/usr/bin/perl

use LWP::Simple;

{

if (@ARGV[0] eq "")
{
print "Usage: weirdness.pl <URL>\n";
exit;
}
$url = @ARGV[0];

$buffer = get "$url";

$buffer =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;

$length = length($buffer);
@uppers = ($buffer =~ /([A-Z])/g);
@lowers = ($buffer =~ /([a-z])/g);
$num_upper = @uppers;
$num_lower = @lowers;


print "Non-html chars: $length\n";
print "upper chars: $num_upper\n";
print "lower chars: $num_lower\n\n";

#$score = $num_upper/$num_lower;
$ratio = $num_upper/$num_lower;
$score = $ratio * $length;
printf("upper-to-lower ratio: %.2f\n", $ratio);
printf("Weirdness score: %.2f\n", $score);