Advertisement
Guest User

price grabber

a guest
Nov 2nd, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. <?php
  2. include ("string_functions.php");
  3.  
  4. /*
  5. inventoryObjects_prices.php is used to update prices of an inventory object
  6. it will update just the grand exchange price if the other values (high alch, low alch) exist
  7. if the other values do not exist, then this script will update those as well.
  8. */
  9.  
  10.  
  11.  
  12. $username = "[redacted]"; //predefined user and pass to access db
  13. $password = "[redacted]";
  14. $db_name = "[redacted]"; //name of the database
  15. $table = "[redacted]"; //name of the table
  16. $serverIP = "[redacted]";
  17.  
  18. $itemName = str_replace("_", " ", $_GET['name']);
  19. $updateAll = $_GET['forceAll'];
  20.  
  21. //create the database object using the above parameters
  22.  
  23. $database = new mysqli ($serverIP, $username, $password, $db_name);
  24.  
  25. if ($database -> connect_errno)
  26. {
  27. //if there is an error, print it
  28. die(printF("Error: Connect failed. Reason: %s<br />", $database -> connect_errno));
  29. }
  30.  
  31. $database -> select_db($table);
  32.  
  33. //adds item to the table if it doesn't already exist
  34. $query = "INSERT IGNORE INTO $table (name) VALUES ('$itemName')";
  35. //$database -> query($query);
  36. if ($result = $database -> query($query))
  37. {
  38. printF('We were able to add the item.');
  39. }else
  40. {
  41. die(printF("Error: Unable to complete the query."));
  42. }
  43. //gets the website source code and parses it into the various parameters
  44. $webpageText = file_get_contents("http://runescape.wikia.com/wiki/" . $_GET['name']);
  45.  
  46. $value = get_string_between($webpageText, '" data-val-each="', '"><span class="infobox-quantity-replace');
  47.  
  48. /*
  49. generates a query that will obtain tradeable and value. from here, we will determine if all aspects need to be updated.
  50. forceAll -> update all
  51. tradeable = yes and price = 0 -> update all
  52. tradeable = yes and price != 0 -> update price
  53. tradeable = no -> update nothing
  54. */
  55.  
  56. $query = "SELECT * FROM $table WHERE name = '$itemName' LIMIT 1";
  57. if ($result = $database -> query($query))
  58. {
  59. //note: we are not checking to see if the item is in the database because we added it earlier
  60.  
  61. $row = $result -> fetch_assoc();
  62. if (($updateAll = 'true') or (($row['tradeable'] == 'true') and ($row['price'] == 0)))
  63. {
  64. $highAlchValue = get_string_between($webpageText, '>High alch</a></th><td>', ' coins</td></tr>');
  65. $lowAlchValue = get_string_between($webpageText, '>Low alch</a></th><td>', ' coins</td></tr>');
  66. printF('<br />lowalch = %s<br />highalch = %s<br />geval = %s<br />', $lowAlchValue, $highAlchValue, $value);
  67.  
  68. //printF('%s', $webpageText);
  69. if (strToLower(get_string_between($webpageText, 'Stacks in bank</th><td>', '</td></tr>')) == 'no')
  70. {
  71. $stacks = 'false';
  72. $stacksInBank = 'false';
  73. }else
  74. {
  75. $stacksInBank = 'true';
  76. if (strToLower(get_string_between($webpageText, '>Stackable</a></th><td>', '</td></tr>')) == 'yes')
  77. {
  78. $stacks = 'true';
  79. }else
  80. {
  81. $stacks = 'false';
  82. }
  83. }
  84.  
  85. if (strToLower(get_string_between($webpageText, '>Tradeable</a></th><td>', '</td></tr>')) == 'yes')
  86. {
  87. $tradeable = 'true';
  88. }else
  89. {
  90. $tradeable = 'false';
  91. }
  92.  
  93. //generates a query to update all of the values that we just obtained into the table
  94. $query = "UPDATE $table SET value = '$value', highAlchValue = '$highAlchValue', lowAlchValue = '$lowAlchValue', stacks = '$stacks', stacksInBank = '$stacksInBank', tradeable = '$tradeable' WHERE $table.name = '$itemName'";
  95. if (! $result = $database -> query($query))
  96. {
  97. die(printF("Error: could not update the database."));
  98. }else
  99. {
  100. PrintF('Successfully updated the database!');
  101. }
  102.  
  103. //this part makes the regular DTM and the noteDTM the same if the item is stackable
  104. $query = "SELECT * FROM $table WHERE name = '$itemName' LIMIT 1";
  105. if ($result = $database -> query($query))
  106. {
  107. $row = $result -> fetch_assoc();
  108. if ($row['stacks'] = 'true')
  109. {
  110. printF('we did it');
  111. $query = "UPDATE $table SET noteDTM = '$row[DTM]' WHERE $table.name = '$row[name]'";
  112. $database -> query($query);
  113. }
  114. }
  115. }else
  116. {
  117. //generates a query to update the price of the item
  118. $query = "UPDATE $table SET value = '$value' WHERE $table.name = '$itemName'";
  119. if (! $result = $database -> query($query))
  120. {
  121. die(printF("Error: Could not update the database."));
  122. }else
  123. {
  124. printF("Successfully updated the price of %s", $itemName);
  125. $result -> close();
  126. }
  127. }
  128. }
  129.  
  130. $database -> close();
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement