Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package darkww;
- import java.awt.Desktop;
- import java.awt.Toolkit;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintStream;
- import java.io.PrintWriter;
- import java.io.UnsupportedEncodingException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.nio.charset.StandardCharsets;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- import java.util.ResourceBundle;
- import java.util.Timer;
- import java.util.TimerTask;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import java.util.prefs.Preferences;
- import javafx.application.Platform;
- import javafx.beans.property.SimpleIntegerProperty;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Alert.AlertType;
- import javafx.scene.control.Button;
- import javafx.scene.control.Control;
- import javafx.scene.control.Label;
- import javafx.scene.control.RadioButton;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.ToggleGroup;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.firefox.FirefoxOptions;
- /**
- *
- * @author Piotr
- */
- public class FXMLDocumentController implements Initializable {
- @FXML
- private Label labelKoniec, labelTimer, labelTimer1;
- @FXML
- private TextArea ta1, ta2;
- @FXML
- private Button button, button1, buttonPrzerwij;
- @FXML
- private RadioButton radiotz, radiotp;
- // @FXML
- //private ToggleGroup group;
- WebDriver fb = null;
- @FXML
- private void handleButtonAction(ActionEvent event) throws FileNotFoundException {
- labelTimer.setText("");
- if (ta1.getText().trim().isEmpty()) {
- alert();
- ta1.clear();
- ta1.requestFocus();
- } else {
- Timer timer1 = new Timer();
- MyTimerTask timer1_task = new MyTimerTask();
- timer1.schedule(timer1_task, 0, 1000);
- labelKoniec.setText("KONIEC");
- ta2.clear();
- labelKoniec.setVisible(false);
- editableButton(true);
- button1.setDisable(true);
- new Thread(() -> {
- boolean czyLinkObslugiwany = true;
- try {
- FileOutputStream writer = new FileOutputStream("src/linki.txt");
- zapiszDoPliku(ta1.getText(), "linki");
- FileOutputStream writer1 = new FileOutputStream("src/wygenerowane.txt");
- List<String> linki = Files.readAllLines(Paths.get("src/linki.txt"), StandardCharsets.UTF_8);
- List<String> konta = Files.readAllLines(Paths.get("src/konta.txt"), StandardCharsets.UTF_8);
- System.setProperty("webdriver.gecko.driver", "C://gecodriver/geckodriver.exe");
- System.setProperty("webdriver.firefox.bin", "C:\\Users\\Piotr\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
- FirefoxOptions options = new FirefoxOptions();
- if (radiotz.isSelected()) {
- options.addArguments("--headless");
- }
- fb = new FirefoxDriver(options);
- System.out.println("selenium uruchomione");
- Platform.runLater(() -> buttonPrzerwij.setDisable(false));
- Preferences p = Preferences.userRoot();
- int index = p.getInt("darkw", 0);
- if (index < 0 || index > konta.size() - 1) {
- index = 0;
- p.putInt("darkw", 0);
- }
- //int index = 0;
- System.out.println("rejestr: " + p.getInt("darkw", 0) + " liczba kont: " + konta.size());
- p:
- for (int i = 0; i < linki.size(); i++) {
- fb.get(linki.get(i));
- List<String> hostingi;
- try {
- hostingi = host(linki.get(i));
- } catch (Exception e) {
- System.out.println("wygasniety link");
- continue;
- }
- String rozmiar = "";
- String strona = "";
- if (hostingi.size() == 2) {
- rozmiar = hostingi.get(0);
- strona = hostingi.get(1);
- } else {
- System.out.println("nieobslugiwany link: " + linki.get(i));
- System.out.println("generowanie przerwane");
- czyLinkObslugiwany = false;
- Platform.runLater(() -> labelKoniec.setText("Nieobsługiwany link"));
- break p;
- }
- fb.get("https://darkw.pl/new-topic-f7/");
- // Random r = new Random();
- // int index = r.nextInt(7);
- if (index == konta.size()) {
- index = 0;
- }
- String[] loginHaslo = konta.get(index).split(":");
- fb.findElement(By.cssSelector("input[name='loginUserLogin']")).sendKeys(loginHaslo[0]);
- fb.findElement(By.cssSelector("input[name='loginUserPass']")).sendKeys(loginHaslo[1]);
- index++;
- p.putInt("darkw", index);
- fb.findElement(By.cssSelector("button[onclick='loader(); document.userLogin.submit();'")).click();
- fb.findElement(By.cssSelector("input[name='postTitle']")).sendKeys(strona + " " + rozmiar);
- fb.findElement(By.cssSelector("textarea[name='postMessage']")).sendKeys("[code]" + linki.get(i) + "[/code]");
- fb.findElement(By.cssSelector("div[onclick=\"$('#postOption').val('0'); loader(); document.newTopic.submit();\"")).click();
- System.out.println("dodaje post: " + (1 + i) + " z " + linki.size());
- // ustawPole("dodaję post: " + (1 + i) + " z " + linki.get(i));
- //Thread.sleep(45000);
- int licznik = 0;
- labelTimer1.setVisible(true);
- while (true) {
- Timer timer2 = new Timer();
- MyTimerTask1 timer2_task = new MyTimerTask1();
- timer2.schedule(timer2_task, 0, 1000);
- Thread.sleep(10000);
- timer2_task.cancel();
- fb.get(fb.getCurrentUrl());
- List<WebElement> code = fb.findElements(By.cssSelector("code"));
- if (code.size() > 1) {
- System.out.println("zapis do pliku: " + code.get(1).getText());
- zapiszDoPliku(code.get(1).getText(), "wygenerowane");
- String content = new String(Files.readAllBytes(Paths.get("src/wygenerowane.txt")), "UTF-8");
- ta2.setText(content);
- ta2.positionCaret(content.length());
- //System.out.println(code.get(1).getText());
- fb.get("https://darkw.pl/logout/");
- break;
- } else {
- licznik++;
- //Thread.sleep(10000);
- System.out.println("Odswiezam post: " + (1 + i) + " z " + linki.size());
- // ustawPole("Odświeżam post: " + fb.getCurrentUrl());
- System.out.println("licznik: " + licznik);
- //ustawPole("licznik: " + licznik);
- }
- if (licznik == 24) {
- i--;
- fb.get("https://darkw.pl/logout/");
- System.out.println("continue");
- // ustawPole("continue");
- continue p;
- }
- }
- }
- fb.quit();
- timer1_task.stop();
- if (czyLinkObslugiwany) {
- String content = new String(Files.readAllBytes(Paths.get("src/wygenerowane.txt")), "UTF-8");
- StringSelection stringSelection = new StringSelection(content);
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(stringSelection, null);
- ta2.setText(content);
- }
- labelKoniec.setVisible(true);
- editableButton(false);
- labelTimer1.setVisible(false);
- Platform.runLater(() -> buttonPrzerwij.setDisable(true));
- Platform.runLater(() -> button1.setDisable(false));
- //System.out.println("koniec");
- // ustawPole("koniec");
- //System.exit(0);
- } catch (IOException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- System.out.println(ex.getMessage());
- fb.quit();
- editableButton(false);
- Platform.runLater(() -> buttonPrzerwij.setDisable(true));
- Platform.runLater(() -> button1.setDisable(false));
- timer1_task.stop();
- } catch (InterruptedException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- System.out.println(ex.getMessage());
- fb.quit();
- editableButton(false);
- timer1_task.stop();
- Platform.runLater(() -> buttonPrzerwij.setDisable(true));
- Platform.runLater(() -> button1.setDisable(false));
- } catch (Exception ex) {
- try {
- fb.quit();
- timer1_task.stop();
- System.out.println(ex.getMessage());
- } catch (Exception e) {
- System.out.println("przerwane przez uzytkownika");
- timer1_task.stop();
- }
- editableButton(false);
- Platform.runLater(() -> buttonPrzerwij.setDisable(true));
- Platform.runLater(() -> button1.setDisable(false));
- }
- }).start();
- }
- }
- @FXML
- private void otworzWygenerowane(ActionEvent event) throws IOException {
- Desktop.getDesktop().open(new File("src/wygenerowane.txt"));
- }
- @FXML
- private void otworzLinki(ActionEvent event) throws IOException {
- Desktop.getDesktop().open(new File("src/wypucowane.txt"));
- }
- @FXML
- private void otworzWypucowane(ActionEvent event) throws IOException {
- Desktop.getDesktop().open(new File("src/wypucowane.txt"));
- }
- @FXML
- private void otworzDobre(ActionEvent event) throws IOException {
- Desktop.getDesktop().open(new File("src/dobre.txt"));
- }
- @FXML
- private void sprawdzLinki(ActionEvent event) throws IOException {
- ta2.clear();
- labelKoniec.setText("KONIEC");
- labelKoniec.setVisible(false);
- FileOutputStream writer = new FileOutputStream("src/dobre.txt");
- FileOutputStream writer1 = new FileOutputStream("src/wypucowane.txt");
- new Thread(() -> {
- try {
- Timer timer1 = new Timer();
- MyTimerTask timer1_task = new MyTimerTask();
- timer1.schedule(timer1_task, 0, 1000);
- String linki[] = ta1.getText().split("\n");
- java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
- Document doc = null;
- double rozmiarc = 0;
- int wypucowane = 0;
- int dobre = 0;
- for (int i = 0; i < linki.length; i++) {
- try {
- doc = Jsoup.connect(linki[i]).get();
- String rozmiar = doc.select(".title>small").text();
- Platform.runLater(() -> {
- ta2.clear();
- });
- System.out.println((1 + i) + " z " + linki.length);
- if (rozmiar.trim().isEmpty()) {
- zapiszDoPliku(linki[i], "wypucowane");
- System.out.println("wypucowane");
- wypucowane++;
- } else {
- zapiszDoPliku(linki[i], "dobre");
- dobre++;
- String m[] = rozmiar.split(" ");
- double rd = Double.parseDouble(m[0]);
- if (m[1].equals("MB")) {
- //System.out.println("mb");
- rd = Double.parseDouble(m[0]) / 1024;
- }
- rozmiarc += rd;
- }
- } catch (IOException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- String content = new String(Files.readAllBytes(Paths.get("src/dobre.txt")), "UTF-8");
- Platform.runLater(() -> {
- ta2.clear();
- });
- System.out.println("wypucowane linki: " + wypucowane);
- System.out.println("rozmiar wszystkich linkow: " + df.format(rozmiarc) + " GB");
- System.out.println("dobre linki: " + dobre);
- System.out.println("wszystkie linki: " + linki.length);
- System.out.println("dobre: ");
- System.out.println("");
- Platform.runLater(() -> {
- ta2.appendText(content);
- });
- labelKoniec.setVisible(true);
- timer1_task.stop();
- } catch (UnsupportedEncodingException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }).start();
- }
- @FXML
- private void breakSelenium(ActionEvent event) throws IOException {
- Platform.runLater(() -> {
- fb.close();
- buttonPrzerwij.setDisable(true);
- button.setDisable(false);
- });
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- /* SimpleIntegerProperty count = new SimpleIntegerProperty(20);
- int rowHeight = 10;
- ta1.prefHeightProperty().bindBidirectional(count);
- ta1.minHeightProperty().bindBidirectional(count);
- ta1.maxHeight(20);
- ta1.scrollTopProperty().addListener(new ChangeListener<Number>() {
- @Override
- public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
- if (newVal.intValue() > rowHeight && newVal.intValue()<20) {
- count.setValue(count.get() + newVal.intValue());
- }
- }
- });*/
- Platform.runLater(() -> ta1.requestFocus());
- OutputStream out = new OutputStream() {
- @Override
- public void write(int b) throws IOException {
- appendText(String.valueOf((char) b));
- }
- };
- System.setOut(new PrintStream(out, true));
- }
- public void appendText(String str) {
- Platform.runLater(() -> ta2.appendText(str));
- }
- public void editableButton(boolean t) {
- Platform.runLater(() -> button.setDisable(t));
- }
- public static void zapiszDoPliku(String text, String nazwa) {
- try (FileWriter fw = new FileWriter("src/" + nazwa + ".txt", true);
- BufferedWriter bw = new BufferedWriter(fw);
- PrintWriter out = new PrintWriter(bw)) {
- out.println(text);
- } catch (IOException e) {
- System.out.println("brak pliku");
- }
- }
- public List<String> host(String link) throws MalformedURLException {
- List<String> hosty = new ArrayList<>();
- if (link.contains("rapidu.net")) {
- hosty.add(fb.findElement(By.cssSelector(".title>small")).getText().replace(".", ","));
- } else if (link.contains("fileshark.pl")) {
- hosty.add(fb.findElement(By.cssSelector(".size-file > strong:nth-child(1)")).getText().replace(".", ","));
- }
- //System.out.println("host = " + getDomain(link));
- hosty.add(getDomain(link));
- return hosty;
- }
- public String getDomain(String link) throws MalformedURLException {
- URL url = new URL(link);
- return url.getHost().replace("www.", "").replaceAll("\\..*", "");
- }
- public void alert() {
- Alert alert = new Alert(AlertType.ERROR);
- alert.setTitle("Info");
- alert.setHeaderText(null);
- alert.setContentText("Nie podałeś żadnych linków!");
- alert.showAndWait();
- }
- class MyTimerTask extends TimerTask {
- int sekundy = 0;
- int minuty = 0;
- int godziny = 0;
- String g;
- String m;
- String s;
- public void run() {
- sekundy++;
- if (sekundy == 60) {
- minuty++;
- sekundy = 0;
- if (minuty == 60) {
- godziny++;
- minuty = 0;
- }
- }
- g = godziny + "";
- m = minuty + "";
- s = sekundy + "";
- if (godziny < 10) {
- g = "0" + godziny;
- }
- if (minuty < 10) {
- m = "0" + minuty;
- }
- if (sekundy < 10) {
- s = "0" + sekundy;
- }
- Platform.runLater(() -> labelTimer.setText("czas działania: " + g + ":" + m + ":" + s));
- }
- public void stop() {
- cancel();
- }
- }
- class MyTimerTask1 extends TimerTask {
- int sekundy = 10;
- public void run() {
- // if (sekundy < 10) {
- // s = "0" + sekundy;
- //}
- Platform.runLater(() -> labelTimer1.setText("odświeżam post za: " + sekundy + " s"));
- sekundy--;
- }
- public void stop() {
- Platform.runLater(() -> labelTimer1.setText(""));
- cancel();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement