Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.*;
- import org.jsoup.select.Elements;
- public class ItemBot {
- public static String url = "jdbc:mysql://localhost:3306/jaydenm1_Users?useSSL=false";
- public static String user = "jaydenm1_main";
- public static String pass = "H?g5Cs0gb]GF";
- public static int userId = -1;
- public static int page = 1;
- public static double user_points = 0;
- public static String itemName = null;
- public static Elements getLink = null;
- public static double finduserItems(int argId) throws Exception {
- userId = argId;
- Connection connection = DriverManager.getConnection(url, user, pass);
- Element itemnameQuery = null;
- int item = 0;
- int itemCount = 0;
- int page_item = 0;
- Document dom;
- while (true) {
- try {
- dom = Jsoup.connect("http://www.bloxcity.com/user/getInventory.php?UserID="+userId+"&ItemType=hat&Page="+page).data("query", "Java")
- .userAgent("Mozilla")
- .cookie("auth", "token")
- .timeout(10000)
- .get();
- }
- catch (Exception e) {
- System.out.println("ID: " + userId + " - Failed to connect");
- continue;
- }
- if (dom.select("a").size() == 0) {
- System.out.println("ID: " + userId + " - No items on page");
- return user_points;
- }
- try {
- getLink = dom.select("a");
- } catch (Exception e) {
- System.out.println("ID: " + userId + " - Failed to find a");
- continue;
- }
- try {
- itemnameQuery = getLink.get(item + 1);
- } catch (Exception e) {
- System.out.println("ID: " + userId + " - End of page (Added: "+(itemCount)+" items total, "+page_item+" on page)");
- page++;
- page_item = 0;
- item = 0;
- System.out.println("Page "+page);
- continue;
- }
- itemName = itemnameQuery.text().replace("'", "''");
- boolean added = false;
- ResultSet db_checkItem = connection.createStatement().executeQuery("SELECT COUNT(*) FROM item_table WHERE Name='"+itemName+"'");
- itemName = itemnameQuery.text();
- while (db_checkItem.next()) {
- if (db_checkItem.getInt(1) == 0) {
- int additemQuery = addItem(item, getLink);
- if (additemQuery == 1) {
- added = true;
- }
- } else {
- ResultSet db_getItem = connection.createStatement().executeQuery("SELECT Price FROM item_table WHERE Name='"+itemName.replace("'", "''")+"'");
- while (db_getItem.next()) {
- int getitemPrice = db_getItem.getInt(1);
- if (getitemPrice != -1) {
- user_points = user_points + (getitemPrice * 0.0025);
- } else {
- user_points = user_points + .5;
- }
- }
- }
- }
- System.out.println("ID: " + userId + " - Item #" + ((item / 3)+1) + " - Name: "+itemName+" - Points: "+user_points+" - Added: "+added);
- item = item + 3;
- if (added == true) {
- page_item++;
- itemCount++;
- }
- }
- }
- public static int addItem(int itemNumb, Elements getLink) throws Exception {
- Connection connection = DriverManager.getConnection(url, user, pass);
- Element link = null;
- try {
- link = getLink.get(itemNumb);
- } catch (Exception e) {
- System.out.println("ID: " + userId + " - End of page");
- return 2;
- }
- int priceCost = itemPrice(link.attr("href"));
- int itemId = Integer.parseInt(link.attr("href").replace("/", "").replace("https:www.bloxcity.commarket", ""));
- try {
- PreparedStatement queueInsert = connection.prepareStatement("INSERT INTO item_table (ItemID, Name, Price) VALUES(?,?,?)");
- queueInsert.setInt(1, itemId);
- queueInsert.setString(2, itemName);
- queueInsert.setInt(3, priceCost);
- queueInsert.executeUpdate();
- } catch (SQLException e) {
- System.out.println("Error inserting into item table");
- return 3;
- }
- if (priceCost != -1) {
- user_points = user_points + (priceCost * 0.0025);
- } else {
- user_points = user_points + .5;
- }
- return 1;
- }
- public static int itemPrice(String itemUrl) throws Exception {
- Document itempage = null;
- Element costQuery = null;
- String costReplace = null;
- int cost = -1;
- try {
- itempage = Jsoup.connect(itemUrl).data("query", "Java")
- .userAgent("Mozilla")
- .cookie("auth", "token")
- .timeout(10000)
- .get();
- } catch (Exception e) {
- System.out.println("Cannot connect to item page");
- }
- try {
- int costType = -1;
- costQuery = itempage.select("div[class=col s12 m3 l3 center-align]").select("a").get(0);
- if (costQuery.text().contains("CASH")) { costType = 10; } else if (costQuery.text().contains("COINS")) { costType = 1; }
- costReplace = costQuery.text().replace(" ", "").replace("BUYFOR", "").replace("COINS", "").replace("CASH", "");
- cost = Integer.parseInt(costReplace) * costType;
- } catch (Exception e) {
- System.out.println("Error finding price. URL: " + itemUrl);
- return -1;
- }
- return cost;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement