NDS Game Price Checker script

Discussion in 'NDS - Console and Game Discussions' started by Lassik, Dec 31, 2010.

  1. Lassik

    Lassik Advanced Member

    Nov 19, 2010
    United States
    Not sure if anyone would find this useful but I figured i'd post it anyways since someone may want to use it.

    I had a rather large list of games that I wanted to check the prices on to see which was the cheapest. I didn't know of an easy way to check them all at once so I made a script to do it for me. It's written in PHP and HTML. It would need to be run on a server with PHP installed. That's very common these days so it wouldn't be hard to find.

    It's nothing complicated and I commented the crap out of it in case anyone wanted to edit it. Probably more comments than actual code. I know there's a million different (and probably better) ways to write this but I wasn't going for perfection.

    To use it, just copy and paste the code in to a file and name it <whatever>.php then upload it to your PHP enabled server and run it. I tried to make it in a way that would be easy (sort of) to add additional sites for anyone who wanted to do that.

    If anyone wants to use this you are more than welcome to do whatever you want with it and even claim you made it for all I care.

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?PHP
    *ÂÂÂÂÂÂ NDS Price Checker v1.1ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ *
    * This script was created to make it easierÂÂ*
    * to find the price of multiple games. UsesÂÂ*
    * for this would be for example if you found *
    * a list of games online and you just wanted *
    * to buy which ever games were the cheapestÂÂ*
    * off that list. You could just put the list *
    * directly in to the box and check them all. *

    * The following function is what goesÂÂ*
    * out and grabs the data from the page *
    * and parses out the price.ÂÂÂÂÂÂÂÂÂÂÂÂ*
    function getp($str, $site)

    ÂÂ * The following Switch determines whatÂÂ *
    ÂÂ * format the URL, Game Name and RegularÂÂ*
    ÂÂ * Expression need to be in depending onÂÂ*
    ÂÂ * the site you've chosen to search forÂÂ *
    ÂÂ * prices on. If you'd like to add yourÂÂ *
    ÂÂ * own site, just copy from "case" toÂÂÂÂ *
    ÂÂ * "break;" and edit the data accordingly *
    ÂÂ ******************************************/ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂswitch ($site) {
    ÂÂÂÂÂÂcase "google":

    ÂÂÂÂÂÂÂÂÂÂ * Google's query URL replaces spaces with + *
    ÂÂÂÂÂÂÂÂÂÂ * so this is what is being done here toÂÂÂÂ *
    ÂÂÂÂÂÂÂÂÂÂ * insure we get the results. "Nintendo DS"ÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ * is also being added to the string toÂÂÂÂÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ * insure it only finds the Nintendo DSÂÂÂÂÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str)."+Nintendo+DS";

    ÂÂÂÂÂÂÂÂÂÂ * Putting the URL together with the string *
    ÂÂÂÂÂÂÂÂÂÂ ********************************************/ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://www.google.com/search?q=".$str."&tbs=shop:1";
    ÂÂÂÂÂÂÂÂÂÂ * Setting the string for the Regular ExpressionÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ * search that is going to be performed later.ÂÂÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ * This is just basically obtained by viewing the *
    ÂÂÂÂÂÂÂÂÂÂ * source of the page itself that displays theÂÂÂÂ*
    ÂÂÂÂÂÂÂÂÂÂ * price we're trying to grab. Then take the code *
    ÂÂÂÂÂÂÂÂÂÂ * surrounding code and place "(.*?)" where theÂÂ *
    ÂÂÂÂÂÂÂÂÂÂ * price is so that it will be grabbed.ÂÂÂÂÂÂÂÂÂÂ *
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!></a></div><div class=psliprice><div><b>(.*?)</b>!";
    ÂÂÂÂÂÂcase "amazon":
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str);
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://www.amazon.com/s/ref=nb_sb_noss?url=node%3D11075831&field-keywords=".$str;
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!from <span.*>(.*?)</span></span>!";
    ÂÂÂÂÂÂcase "ebay":
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str);
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://video-games.shop.ebay.com/Video-Games-/1249/i.html?Platform=Nintendo%2520DS&rt=nc&_nkw=".
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ $str."&_dmpt=Video_Games_Games&_sticky=1&_sop=15&_sc=1";
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!<td class=\"prc\"><div class=\"g-b\">(.*?)</div><span!";
    ÂÂÂÂÂÂcase "gamestop":
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str);
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://www.gamestop.com/browse/search.aspx?dsNav=Ntk:TitleKeyword|".$str."|1|,N:382-134";
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!<p class=\"pricing\".*>(.*?)</p>!";
    ÂÂÂÂÂÂcase "example_site":
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str);
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://www.example.com".$str;
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!some code (.*?) some more code!";
    ÂÂÂÂÂÂÂÂÂÂ * Just incase somehow a site is notÂÂÂÂ *
    ÂÂÂÂÂÂÂÂÂÂ * selected, google will be the default. *
    ÂÂÂÂÂÂÂÂÂÂ *****************************************/ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ
    ÂÂÂÂÂÂÂÂÂÂ$str = preg_replace("/\s/", "+", $str)."+Nintendo+DS";
    ÂÂÂÂÂÂÂÂÂÂ$url = "http://www.google.com/search?q=".$str."&tbs=shop:1";
    ÂÂÂÂÂÂÂÂÂÂ$regex = "!></a></div><div class=psliprice><div><b>(.*?)</b>!";

    ÂÂ$a = file_get_contents($url);
    ÂÂif (preg_match($regex, $a, $m))
    ÂÂÂÂ$price = "<a href='".$url."' target='result'>".trim($m[1], '?')."</a>";
    ÂÂ}else {
    ÂÂÂÂ$price = "<a href='".$url."' target='result'>"."Not Found!"."</a>";
    ÂÂreturn $price;

    $site = "";
    $gamelist = "";

    * Only perform the following actions *
    * if the button has been clicked toÂÂ*
    * check for prices and games are inÂÂ*
    * the search box.ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ*
    if ($_POST) {
    ÂÂ * Start building the initial headerÂÂ*
    ÂÂ * of the table that will display the *
    ÂÂ * games and prices.ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ*
    ÂÂ **************************************/ÂÂÂÂÂÂÂÂÂÂ
    ÂÂ$content = "<table border='1'><tr><td><b>Game</b></td><td><b>Price</b></td></tr>";

    ÂÂ * Grab all the games submitted to beÂÂ *
    ÂÂ * checked and store them in a variable *
    ÂÂ ****************************************/ÂÂÂÂÂÂÂÂ
    ÂÂ$gamelist = $_POST['gamelist'];

    ÂÂ * Grab all the games submitted to beÂÂ *
    ÂÂ * checked and store them in a variable *
    ÂÂ ****************************************/ÂÂÂÂÂÂÂÂ
    ÂÂ$site = $_POST['site'];

    ÂÂ * Cleaning up the text a little toÂÂÂÂ*
    ÂÂ * improve chances of finding the game *
    ÂÂ ***************************************/ÂÂÂÂÂÂÂÂ
    ÂÂ$gamelist = str_replace("\"", " ", $gamelist);
    ÂÂ$gamelist = str_replace("&", "and", $gamelist);
    ÂÂ$gamelist = str_replace("'", "", $gamelist);
    ÂÂ$gamelist = str_replace(" -", ":", $gamelist);
    ÂÂ$gamelist = str_replace(")", "", $gamelist);
    ÂÂ$gamelist = str_replace("(", "", $gamelist);
    ÂÂ$gamelist = str_replace("\\", "", $gamelist);
    ÂÂ * Splitting text up in to an array byÂÂ*
    ÂÂ * separating them by the hidden Return *
    ÂÂ * and New Line charactersÂÂÂÂÂÂÂÂÂÂÂÂÂÂ*
    ÂÂ ****************************************/ÂÂ
    ÂÂ$gamearray = preg_split("/\r\n/", $gamelist);

    ÂÂ * Looping through the array and sendingÂÂ *
    ÂÂ * each value to the getp() function toÂÂÂÂ*
    ÂÂ * get the game's price and return it back *
    ÂÂ *******************************************/ÂÂÂÂÂÂÂÂÂÂ
    ÂÂforeach ($gamearray as $game) {
    ÂÂÂÂ$content .= "<tr><td>".$game."</td><td>".getp($game, $site)."</td></tr>";
    ÂÂ$content .= "</table>";

    }else {
    ÂÂ * Display this on the page if no *
    ÂÂ * search has been performedÂÂÂÂÂÂ*
    ÂÂ **********************************/ÂÂÂÂÂÂÂÂ
    ÂÂ$content = "Enter your list of games and click the Check Prices button.";

    ÂÂÂÂ<title>NDS Price Checker</title>
    ÂÂÂÂ<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="POST">
    ÂÂÂÂÂÂ<b>Site to use:</b>
    ÂÂÂÂÂÂ<select name='site'>
    ÂÂÂÂÂÂÂÂ<option value='google'<?PHP if ($site == "google") echo " selected"; ?>>Google</option>
    ÂÂÂÂÂÂÂÂ<option value='amazon'<?PHP if ($site == "amazon") echo " selected"; ?>>Amazon</option>
    ÂÂÂÂÂÂÂÂ<option value='ebay'<?PHP if ($site == "ebay") echo " selected"; ?>>eBay</option>
    ÂÂÂÂÂÂÂÂ<option value='gamestop'<?PHP if ($site == "gamestop") echo " selected"; ?>>GameStop</option>
    ÂÂÂÂÂÂ</select><br />
    ÂÂÂÂÂÂ<textareaÂÂcols='60' rows='20' name='gamelist' id='gamelist'><?PHP echo $gamelist; ?></textarea><br />
    ÂÂÂÂÂÂ<input type="submit" value="Check Prices" name="check">
    ÂÂÂÂÂÂ<input type="button" value="Clear Field" name="clear" onclick='java script:gamelist.value="";gamelist.focus()'>
    ÂÂÂÂ<br />
    ÂÂÂÂ<?PHP echo $content; ?>

    P.S. I know I gave it a version number but this is not something I intend on updating. It served it's purpose for me and i'm just passing it on.

    EDIT: Ok... maybe 1 update...
  2. Rydian

    Rydian Resident Furvert™

    Feb 4, 2010
    United States
    Cave Entrance, Watching Cyan Write Letters
    Dude, that kind of commenting is like porn for nerds.
  3. Lassik

    Lassik Advanced Member

    Nov 19, 2010
    United States
    Haha yeah. It's required at my job so I get used to it.
  4. Rydian

    Rydian Resident Furvert™

    Feb 4, 2010
    United States
    Cave Entrance, Watching Cyan Write Letters
    Heh, here's the sort of stuff I tend to do.

    Warning: Spoilers inside!
  5. Lassik

    Lassik Advanced Member

    Nov 19, 2010
    United States
    Ok. So I decided to do 1 update. I added the ability to search eBay and GameStop. Even though GameStop has a very shitty search feature...

    I also put in a few other minor changes.

    Another thing... For anyone interested in trying this out but don't know how to set up a server with PHP here's a link to a site that lists a few FREE hosting services that have PHP installed.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice