Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include ("string_functions.php");
- /*
- inventoryObjects_prices.php is used to update prices of an inventory object
- it will update just the grand exchange price if the other values (high alch, low alch) exist
- if the other values do not exist, then this script will update those as well.
- */
- $username = "[redacted]"; //predefined user and pass to access db
- $password = "[redacted]";
- $db_name = "[redacted]"; //name of the database
- $table = "[redacted]"; //name of the table
- $serverIP = "[redacted]";
- $itemName = str_replace("_", " ", $_GET['name']);
- $updateAll = $_GET['forceAll'];
- //create the database object using the above parameters
- $database = new mysqli ($serverIP, $username, $password, $db_name);
- if ($database -> connect_errno)
- {
- //if there is an error, print it
- die(printF("Error: Connect failed. Reason: %s<br />", $database -> connect_errno));
- }
- $database -> select_db($table);
- //adds item to the table if it doesn't already exist
- $query = "INSERT IGNORE INTO $table (name) VALUES ('$itemName')";
- //$database -> query($query);
- if ($result = $database -> query($query))
- {
- printF('We were able to add the item.');
- }else
- {
- die(printF("Error: Unable to complete the query."));
- }
- //gets the website source code and parses it into the various parameters
- $webpageText = file_get_contents("http://runescape.wikia.com/wiki/" . $_GET['name']);
- $value = get_string_between($webpageText, '" data-val-each="', '"><span class="infobox-quantity-replace');
- /*
- generates a query that will obtain tradeable and value. from here, we will determine if all aspects need to be updated.
- forceAll -> update all
- tradeable = yes and price = 0 -> update all
- tradeable = yes and price != 0 -> update price
- tradeable = no -> update nothing
- */
- $query = "SELECT * FROM $table WHERE name = '$itemName' LIMIT 1";
- if ($result = $database -> query($query))
- {
- //note: we are not checking to see if the item is in the database because we added it earlier
- $row = $result -> fetch_assoc();
- if (($updateAll = 'true') or (($row['tradeable'] == 'true') and ($row['price'] == 0)))
- {
- $highAlchValue = get_string_between($webpageText, '>High alch</a></th><td>', ' coins</td></tr>');
- $lowAlchValue = get_string_between($webpageText, '>Low alch</a></th><td>', ' coins</td></tr>');
- printF('<br />lowalch = %s<br />highalch = %s<br />geval = %s<br />', $lowAlchValue, $highAlchValue, $value);
- //printF('%s', $webpageText);
- if (strToLower(get_string_between($webpageText, 'Stacks in bank</th><td>', '</td></tr>')) == 'no')
- {
- $stacks = 'false';
- $stacksInBank = 'false';
- }else
- {
- $stacksInBank = 'true';
- if (strToLower(get_string_between($webpageText, '>Stackable</a></th><td>', '</td></tr>')) == 'yes')
- {
- $stacks = 'true';
- }else
- {
- $stacks = 'false';
- }
- }
- if (strToLower(get_string_between($webpageText, '>Tradeable</a></th><td>', '</td></tr>')) == 'yes')
- {
- $tradeable = 'true';
- }else
- {
- $tradeable = 'false';
- }
- //generates a query to update all of the values that we just obtained into the table
- $query = "UPDATE $table SET value = '$value', highAlchValue = '$highAlchValue', lowAlchValue = '$lowAlchValue', stacks = '$stacks', stacksInBank = '$stacksInBank', tradeable = '$tradeable' WHERE $table.name = '$itemName'";
- if (! $result = $database -> query($query))
- {
- die(printF("Error: could not update the database."));
- }else
- {
- PrintF('Successfully updated the database!');
- }
- //this part makes the regular DTM and the noteDTM the same if the item is stackable
- $query = "SELECT * FROM $table WHERE name = '$itemName' LIMIT 1";
- if ($result = $database -> query($query))
- {
- $row = $result -> fetch_assoc();
- if ($row['stacks'] = 'true')
- {
- printF('we did it');
- $query = "UPDATE $table SET noteDTM = '$row[DTM]' WHERE $table.name = '$row[name]'";
- $database -> query($query);
- }
- }
- }else
- {
- //generates a query to update the price of the item
- $query = "UPDATE $table SET value = '$value' WHERE $table.name = '$itemName'";
- if (! $result = $database -> query($query))
- {
- die(printF("Error: Could not update the database."));
- }else
- {
- printF("Successfully updated the price of %s", $itemName);
- $result -> close();
- }
- }
- }
- $database -> close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement