Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.concurrent.Executors;
- import org.openqa.selenium.By;
- import org.openqa.selenium.JavascriptExecutor;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.Select;
- @SuppressWarnings("unused")
- public class ScrapTFrefresher {
- public static WebDriver driver;
- public static JavascriptExecutor js;
- public static String lastCounts = "000";
- public static String userName;
- public static String password;
- public static String chromedriver;
- public static void main(String[] args) {
- try {
- File config = new File("config.txt");
- if (!config.exists()){
- config.createNewFile();
- BufferedWriter buf = new BufferedWriter(new FileWriter(config, true));
- buf.write("name=username");
- buf.write(System.getProperty("line.separator"));
- buf.write("password=mypassword");
- buf.write(System.getProperty("line.separator"));
- buf.write("chromedriver=C:/Users/MyUserName/Desktop/chromedriver.exe");
- buf.write(System.getProperty("line.separator"));
- buf.close();
- } else {
- List<String> list = new ArrayList<String>();
- BufferedReader br = new BufferedReader(new FileReader(config));
- while (true) {
- String line = br.readLine();
- if (line == null || line.isEmpty()) {
- break;
- }
- list.add(line);
- }
- br.close();
- userName = list.get(0).split("=")[1];
- password = list.get(1).split("=")[1];
- chromedriver = list.get(2).split("=")[1];
- System.setProperty("webdriver.chrome.driver", chromedriver);
- driver = new ChromeDriver();
- driver.get("https://scrap.tf/partswap");
- driver.findElement(By.id("steamAccountName")).sendKeys(userName);
- WebElement pwd = driver.findElement(By.id("steamPassword"));
- pwd.sendKeys(password);
- pwd.submit();
- waitForLogin();
- driver.get("https://scrap.tf/partswap");
- js = (JavascriptExecutor) driver;
- js.executeScript("ScrapTF.Parts.ChooseBuy()");
- while(true){
- Thread.sleep(new Random().nextInt(2000)+1000);
- js.executeScript("ScrapTF.GenericModal.Close()");
- js.executeScript("ScrapTF.Parts.SwitchBots()");
- if (areRobopartsAvailable()){
- driver.findElement(By.id("buy-5700")).clear();
- driver.findElement(By.id("buy-5700")).clear();
- driver.findElement(By.id("buy-5701")).clear();
- driver.findElement(By.id("buy-5702")).clear();
- driver.findElement(By.id("buy-5703")).clear();
- driver.findElement(By.id("buy-5704")).clear();
- driver.findElement(By.id("buy-5705")).sendKeys("999");
- driver.findElement(By.id("buy-5706")).sendKeys("999");
- driver.findElement(By.id("buy-5707")).sendKeys("999");
- getReinforcedIfNeeded();
- js.executeScript("ScrapTF.Parts.Sell()");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void waitForLogin(){
- try{
- while(!driver.getCurrentUrl().startsWith("https://scrap.tf/")) Thread.sleep(100);
- } catch (Exception e){
- e.printStackTrace();
- }
- }
- public static boolean areRobopartsAvailable(){
- boolean Return = false;
- try{
- int a = Integer.parseInt(driver.findElement(By.id("stock-5705")).getText());
- int b = Integer.parseInt(driver.findElement(By.id("stock-5706")).getText());
- int c = Integer.parseInt(driver.findElement(By.id("stock-5707")).getText());
- if (a+b+c>0){
- if (lastCounts.equals(""+a+b+c)){
- Return = false;
- } else {
- Return = true;
- }
- } else {
- Return = false;
- }
- lastCounts = ""+a+b+c;
- } catch (Exception e){
- Return = false;
- }
- return Return;
- }
- public static void getReinforcedIfNeeded(){
- int a = Integer.parseInt(driver.findElement(By.id("stock-5705")).getText());
- int b = Integer.parseInt(driver.findElement(By.id("stock-5706")).getText());
- int c = Integer.parseInt(driver.findElement(By.id("stock-5707")).getText());
- if (((a+b+c) %2 )== 1){
- int n = Integer.parseInt(driver.findElement(By.id("stock-5702")).getText());
- if (n > 0){
- driver.findElement(By.id("buy-5702")).sendKeys("1");
- return;
- }
- n = Integer.parseInt(driver.findElement(By.id("stock-5703")).getText());
- if (n > 0){
- driver.findElement(By.id("buy-5703")).sendKeys("1");
- return;
- }
- n = Integer.parseInt(driver.findElement(By.id("stock-5704")).getText());
- if (n > 0){
- driver.findElement(By.id("buy-5704")).sendKeys("1");
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement