Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. package a;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Random;
  11. import java.util.concurrent.Executors;
  12.  
  13. import org.openqa.selenium.By;
  14. import org.openqa.selenium.JavascriptExecutor;
  15. import org.openqa.selenium.WebDriver;
  16. import org.openqa.selenium.WebElement;
  17. import org.openqa.selenium.chrome.ChromeDriver;
  18. import org.openqa.selenium.support.ui.Select;
  19.  
  20. @SuppressWarnings("unused")
  21. public class ScrapTFrefresher {
  22.  
  23. public static WebDriver driver;
  24. public static JavascriptExecutor js;
  25. public static String lastCounts = "000";
  26. public static String userName;
  27. public static String password;
  28. public static String chromedriver;
  29.  
  30. public static void main(String[] args) {
  31. try {
  32. File config = new File("config.txt");
  33. if (!config.exists()){
  34. config.createNewFile();
  35. BufferedWriter buf = new BufferedWriter(new FileWriter(config, true));
  36. buf.write("name=username");
  37. buf.write(System.getProperty("line.separator"));
  38. buf.write("password=mypassword");
  39. buf.write(System.getProperty("line.separator"));
  40. buf.write("chromedriver=C:/Users/MyUserName/Desktop/chromedriver.exe");
  41. buf.write(System.getProperty("line.separator"));
  42. buf.close();
  43. } else {
  44. List<String> list = new ArrayList<String>();
  45. BufferedReader br = new BufferedReader(new FileReader(config));
  46. while (true) {
  47. String line = br.readLine();
  48. if (line == null || line.isEmpty()) {
  49. break;
  50. }
  51. list.add(line);
  52. }
  53. br.close();
  54. userName = list.get(0).split("=")[1];
  55. password = list.get(1).split("=")[1];
  56. chromedriver = list.get(2).split("=")[1];
  57. System.setProperty("webdriver.chrome.driver", chromedriver);
  58. driver = new ChromeDriver();
  59. driver.get("https://scrap.tf/partswap");
  60. driver.findElement(By.id("steamAccountName")).sendKeys(userName);
  61. WebElement pwd = driver.findElement(By.id("steamPassword"));
  62. pwd.sendKeys(password);
  63. pwd.submit();
  64. waitForLogin();
  65. driver.get("https://scrap.tf/partswap");
  66. js = (JavascriptExecutor) driver;
  67. js.executeScript("ScrapTF.Parts.ChooseBuy()");
  68. while(true){
  69. Thread.sleep(new Random().nextInt(2000)+1000);
  70. js.executeScript("ScrapTF.GenericModal.Close()");
  71. js.executeScript("ScrapTF.Parts.SwitchBots()");
  72. if (areRobopartsAvailable()){
  73. driver.findElement(By.id("buy-5700")).clear();
  74. driver.findElement(By.id("buy-5700")).clear();
  75. driver.findElement(By.id("buy-5701")).clear();
  76. driver.findElement(By.id("buy-5702")).clear();
  77. driver.findElement(By.id("buy-5703")).clear();
  78. driver.findElement(By.id("buy-5704")).clear();
  79. driver.findElement(By.id("buy-5705")).sendKeys("999");
  80. driver.findElement(By.id("buy-5706")).sendKeys("999");
  81. driver.findElement(By.id("buy-5707")).sendKeys("999");
  82. getReinforcedIfNeeded();
  83. js.executeScript("ScrapTF.Parts.Sell()");
  84. }
  85. }
  86. }
  87.  
  88. } catch (Exception e) {
  89. e.printStackTrace();
  90. }
  91. }
  92. public static void waitForLogin(){
  93. try{
  94. while(!driver.getCurrentUrl().startsWith("https://scrap.tf/")) Thread.sleep(100);
  95. } catch (Exception e){
  96. e.printStackTrace();
  97. }
  98. }
  99. public static boolean areRobopartsAvailable(){
  100. boolean Return = false;
  101. try{
  102. int a = Integer.parseInt(driver.findElement(By.id("stock-5705")).getText());
  103. int b = Integer.parseInt(driver.findElement(By.id("stock-5706")).getText());
  104. int c = Integer.parseInt(driver.findElement(By.id("stock-5707")).getText());
  105. if (a+b+c>0){
  106. if (lastCounts.equals(""+a+b+c)){
  107. Return = false;
  108. } else {
  109. Return = true;
  110. }
  111. } else {
  112. Return = false;
  113. }
  114. lastCounts = ""+a+b+c;
  115. } catch (Exception e){
  116. Return = false;
  117. }
  118. return Return;
  119. }
  120. public static void getReinforcedIfNeeded(){
  121. int a = Integer.parseInt(driver.findElement(By.id("stock-5705")).getText());
  122. int b = Integer.parseInt(driver.findElement(By.id("stock-5706")).getText());
  123. int c = Integer.parseInt(driver.findElement(By.id("stock-5707")).getText());
  124. if (((a+b+c) %2 )== 1){
  125. int n = Integer.parseInt(driver.findElement(By.id("stock-5702")).getText());
  126. if (n > 0){
  127. driver.findElement(By.id("buy-5702")).sendKeys("1");
  128. return;
  129. }
  130. n = Integer.parseInt(driver.findElement(By.id("stock-5703")).getText());
  131. if (n > 0){
  132. driver.findElement(By.id("buy-5703")).sendKeys("1");
  133. return;
  134. }
  135. n = Integer.parseInt(driver.findElement(By.id("stock-5704")).getText());
  136. if (n > 0){
  137. driver.findElement(By.id("buy-5704")).sendKeys("1");
  138. return;
  139. }
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement