Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. import org.jsoup.Jsoup;
  8. import org.jsoup.nodes.*;
  9. import org.jsoup.select.Elements;
  10.  
  11. public class ItemBot {
  12.  
  13. public static String url = "jdbc:mysql://localhost:3306/jaydenm1_Users?useSSL=false";
  14. public static String user = "jaydenm1_main";
  15. public static String pass = "H?g5Cs0gb]GF";
  16.  
  17. public static int userId = -1;
  18. public static int page = 1;
  19. public static double user_points = 0;
  20.  
  21. public static String itemName = null;
  22.  
  23. public static Elements getLink = null;
  24.  
  25. public static double finduserItems(int argId) throws Exception {
  26. userId = argId;
  27.  
  28. Connection connection = DriverManager.getConnection(url, user, pass);
  29.  
  30. Element itemnameQuery = null;
  31.  
  32. int item = 0;
  33. int itemCount = 0;
  34. int page_item = 0;
  35.  
  36. Document dom;
  37.  
  38. while (true) {
  39.  
  40. try {
  41. dom = Jsoup.connect("http://www.bloxcity.com/user/getInventory.php?UserID="+userId+"&ItemType=hat&Page="+page).data("query", "Java")
  42. .userAgent("Mozilla")
  43. .cookie("auth", "token")
  44. .timeout(10000)
  45. .get();
  46. }
  47. catch (Exception e) {
  48. System.out.println("ID: " + userId + " - Failed to connect");
  49. continue;
  50. }
  51.  
  52. if (dom.select("a").size() == 0) {
  53. System.out.println("ID: " + userId + " - No items on page");
  54. return user_points;
  55. }
  56.  
  57. try {
  58. getLink = dom.select("a");
  59. } catch (Exception e) {
  60. System.out.println("ID: " + userId + " - Failed to find a");
  61. continue;
  62. }
  63.  
  64. try {
  65. itemnameQuery = getLink.get(item + 1);
  66. } catch (Exception e) {
  67. System.out.println("ID: " + userId + " - End of page (Added: "+(itemCount)+" items total, "+page_item+" on page)");
  68. page++;
  69. page_item = 0;
  70. item = 0;
  71. System.out.println("Page "+page);
  72. continue;
  73. }
  74.  
  75. itemName = itemnameQuery.text().replace("'", "''");
  76. boolean added = false;
  77.  
  78. ResultSet db_checkItem = connection.createStatement().executeQuery("SELECT COUNT(*) FROM item_table WHERE Name='"+itemName+"'");
  79.  
  80. itemName = itemnameQuery.text();
  81.  
  82. while (db_checkItem.next()) {
  83. if (db_checkItem.getInt(1) == 0) {
  84. int additemQuery = addItem(item, getLink);
  85. if (additemQuery == 1) {
  86. added = true;
  87. }
  88. } else {
  89. ResultSet db_getItem = connection.createStatement().executeQuery("SELECT Price FROM item_table WHERE Name='"+itemName.replace("'", "''")+"'");
  90. while (db_getItem.next()) {
  91. int getitemPrice = db_getItem.getInt(1);
  92. if (getitemPrice != -1) {
  93. user_points = user_points + (getitemPrice * 0.0025);
  94. } else {
  95. user_points = user_points + .5;
  96. }
  97. }
  98. }
  99. }
  100.  
  101. System.out.println("ID: " + userId + " - Item #" + ((item / 3)+1) + " - Name: "+itemName+" - Points: "+user_points+" - Added: "+added);
  102. item = item + 3;
  103. if (added == true) {
  104. page_item++;
  105. itemCount++;
  106. }
  107. }
  108. }
  109.  
  110. public static int addItem(int itemNumb, Elements getLink) throws Exception {
  111.  
  112. Connection connection = DriverManager.getConnection(url, user, pass);
  113.  
  114. Element link = null;
  115.  
  116.  
  117. try {
  118. link = getLink.get(itemNumb);
  119.  
  120. } catch (Exception e) {
  121. System.out.println("ID: " + userId + " - End of page");
  122. return 2;
  123. }
  124.  
  125. int priceCost = itemPrice(link.attr("href"));
  126.  
  127. int itemId = Integer.parseInt(link.attr("href").replace("/", "").replace("https:www.bloxcity.commarket", ""));
  128.  
  129.  
  130. try {
  131. PreparedStatement queueInsert = connection.prepareStatement("INSERT INTO item_table (ItemID, Name, Price) VALUES(?,?,?)");
  132. queueInsert.setInt(1, itemId);
  133. queueInsert.setString(2, itemName);
  134. queueInsert.setInt(3, priceCost);
  135. queueInsert.executeUpdate();
  136. } catch (SQLException e) {
  137. System.out.println("Error inserting into item table");
  138. return 3;
  139. }
  140. if (priceCost != -1) {
  141.  
  142. user_points = user_points + (priceCost * 0.0025);
  143.  
  144. } else {
  145. user_points = user_points + .5;
  146. }
  147. return 1;
  148. }
  149.  
  150. public static int itemPrice(String itemUrl) throws Exception {
  151.  
  152. Document itempage = null;
  153. Element costQuery = null;
  154. String costReplace = null;
  155. int cost = -1;
  156.  
  157.  
  158. try {
  159.  
  160. itempage = Jsoup.connect(itemUrl).data("query", "Java")
  161. .userAgent("Mozilla")
  162. .cookie("auth", "token")
  163. .timeout(10000)
  164. .get();
  165.  
  166. } catch (Exception e) {
  167. System.out.println("Cannot connect to item page");
  168. }
  169.  
  170.  
  171. try {
  172. int costType = -1;
  173.  
  174. costQuery = itempage.select("div[class=col s12 m3 l3 center-align]").select("a").get(0);
  175.  
  176. if (costQuery.text().contains("CASH")) { costType = 10; } else if (costQuery.text().contains("COINS")) { costType = 1; }
  177. costReplace = costQuery.text().replace(" ", "").replace("BUYFOR", "").replace("COINS", "").replace("CASH", "");
  178.  
  179. cost = Integer.parseInt(costReplace) * costType;
  180.  
  181.  
  182. } catch (Exception e) {
  183. System.out.println("Error finding price. URL: " + itemUrl);
  184. return -1;
  185. }
  186.  
  187. return cost;
  188.  
  189. }
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement