Last active
October 18, 2017 01:48
-
-
Save icarofreire/69cdb8aff8cec98aa42ea9a21f2d7cc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package robo; | |
| import java.awt.AWTException; | |
| import java.awt.Robot; | |
| import java.awt.Toolkit; | |
| import java.awt.datatransfer.Clipboard; | |
| import java.awt.datatransfer.DataFlavor; | |
| import java.awt.datatransfer.StringSelection; | |
| import java.awt.datatransfer.Transferable; | |
| import java.awt.datatransfer.UnsupportedFlavorException; | |
| import java.awt.event.KeyEvent; | |
| import java.io.BufferedWriter; | |
| import java.io.FileWriter; | |
| import java.io.IOException; | |
| import java.net.URISyntaxException; | |
| import java.nio.file.Files; | |
| import java.nio.file.Path; | |
| import java.nio.file.Paths; | |
| public class lib_rb { | |
| public Robot rb; | |
| lib_rb(){ | |
| try { | |
| this.rb = new Robot(); | |
| } catch (AWTException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| escrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro OBJETO:" + e.getMessage()); | |
| } | |
| } | |
| // public String clipboard_to_string() { | |
| // Toolkit toolkit = Toolkit.getDefaultToolkit(); | |
| // Clipboard clipboard = toolkit.getSystemClipboard(); | |
| // String result = ""; | |
| // try { | |
| // result = (String) clipboard.getData(DataFlavor.stringFlavor); | |
| // } catch (UnsupportedFlavorException | IOException e) { | |
| // // TODO Auto-generated catch block | |
| // e.printStackTrace(); | |
| // escrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro clipboard_to_string():" + e.getMessage()); | |
| // } | |
| // return result; | |
| // } | |
| /** | |
| * Get the String residing on the clipboard. | |
| * | |
| * @return any text found on the Clipboard; if none found, return an | |
| * empty String. | |
| */ | |
| public String clipboard_to_string() { | |
| String result = ""; | |
| while(true) { | |
| Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
| //odd: the Object param of getContents is not currently used | |
| Transferable contents = clipboard.getContents(null); | |
| boolean hasTransferableText = | |
| (contents != null) && | |
| contents.isDataFlavorSupported(DataFlavor.stringFlavor); | |
| if (hasTransferableText) { | |
| try { | |
| result = (String)contents.getTransferData(DataFlavor.stringFlavor); | |
| } | |
| catch (UnsupportedFlavorException | IOException ex){ | |
| // System.out.println(ex); | |
| // ex.printStackTrace(); | |
| } | |
| } | |
| try { | |
| Thread.sleep(200); | |
| } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } | |
| if(result != "") break; | |
| }//fim while; | |
| return result; | |
| } | |
| public void string_to_clipboard(String str) { | |
| Toolkit toolkit = Toolkit.getDefaultToolkit(); | |
| Clipboard clipboard = toolkit.getSystemClipboard(); | |
| StringSelection strSel = new StringSelection(str); | |
| clipboard.setContents(strSel, null); | |
| } | |
| public void apagar_cb() { | |
| new cb().copiar_para_clipboard("-1"); | |
| } | |
| public void ctrl_a() { | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_A); | |
| this.rb.keyRelease(KeyEvent.VK_A); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| } | |
| public void alt_w() { | |
| this.rb.keyPress(KeyEvent.VK_ALT); | |
| this.rb.keyPress(KeyEvent.VK_W); | |
| this.rb.keyRelease(KeyEvent.VK_W); | |
| this.rb.keyRelease(KeyEvent.VK_ALT); | |
| } | |
| public void ctrl_c() { | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_C); | |
| this.rb.keyRelease(KeyEvent.VK_C); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| } | |
| public void ctrl_v() { | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_V); | |
| this.rb.keyRelease(KeyEvent.VK_V); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| } | |
| public void f6() { | |
| this.rb.keyPress(KeyEvent.VK_F6); | |
| this.rb.keyRelease(KeyEvent.VK_F6); | |
| } | |
| public void enter() { | |
| this.rb.keyPress(KeyEvent.VK_ENTER); | |
| this.rb.keyRelease(KeyEvent.VK_ENTER); | |
| } | |
| public void ctrl_u() {//abrir aba com codigo fonte da pagina; | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_U); | |
| this.rb.keyRelease(KeyEvent.VK_U); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| } | |
| public void fechar_aba() { | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_W); | |
| this.rb.keyRelease(KeyEvent.VK_W); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| } | |
| public void baixar_pagina() { | |
| this.rb.keyPress(KeyEvent.VK_CONTROL); | |
| this.rb.keyPress(KeyEvent.VK_S); | |
| this.rb.keyRelease(KeyEvent.VK_S); | |
| this.rb.keyRelease(KeyEvent.VK_CONTROL); | |
| try { | |
| Thread.sleep(200); | |
| } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } | |
| this.rb.keyPress(KeyEvent.VK_ENTER); | |
| this.rb.keyRelease(KeyEvent.VK_ENTER); | |
| } | |
| public void trocar_janela() { | |
| this.rb.keyPress(KeyEvent.VK_ALT); | |
| this.rb.keyPress(KeyEvent.VK_TAB); | |
| this.rb.keyRelease(KeyEvent.VK_TAB); | |
| this.rb.keyRelease(KeyEvent.VK_ALT); | |
| } | |
| public void f5() { | |
| this.rb.keyPress(KeyEvent.VK_F5); | |
| this.rb.keyRelease(KeyEvent.VK_F5); | |
| } | |
| public void copiar_tudo() { | |
| ctrl_a(); | |
| ctrl_c(); | |
| } | |
| public boolean pegar_dados(int id) { | |
| boolean ok = false; | |
| String dados = ""; | |
| copiar_tudo(); | |
| String clip = ""; | |
| try { | |
| clip = clipboard_to_string(); | |
| if( clip != "-1" ) { | |
| int pin = clip.indexOf("Nº PIN:"); | |
| int sen = clip.indexOf("Altera senha"); | |
| if( pin != -1 && sen != -1 ) { | |
| dados = clip.substring(pin, sen); | |
| dados = dados.replaceAll("\\:\n", ":==>"); | |
| escrever("D:\\Documentos\\projeto-robo\\RES-ROBO.TXT", "ID: " + Integer.toString(id)); | |
| escrever("D:\\Documentos\\projeto-robo\\RES-ROBO.TXT", dados); | |
| escrever("D:\\Documentos\\projeto-robo\\RES-ROBO.TXT", "##################################################################################"); | |
| apagar_cb(); | |
| ok = true; | |
| REescrever("D:\\Documentos\\projeto-robo\\ULTIMO-ID-OBTIDO.TXT", Integer.toString(id)); | |
| }else if( clip.indexOf("A PHP Error was encountered") != -1 ) {//id não existe dentro do sistema; | |
| ok = true; | |
| } | |
| else { | |
| //não obteve os dados; | |
| } | |
| }//fim if; | |
| }catch (java.lang.IllegalStateException e) { | |
| escrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro1 no momento de copiar:" + e.getMessage()); | |
| esperar(10); | |
| pegar_dados(id); | |
| }catch (Exception e) { | |
| escrever("D:\\Documentos\\projeto-robo\\ERRO-CODIGO.TXT", "Erro2 no momento de copiar:" + e.getMessage()); | |
| } | |
| return ok; | |
| } | |
| public void abrir_url(String url) { | |
| try { | |
| java.awt.Desktop.getDesktop().browse(new java.net.URI(url)); | |
| } catch (IOException | URISyntaxException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| } | |
| public void escrever(String arquivo, String conteudo) { | |
| boolean append = true; | |
| try (BufferedWriter bw = new BufferedWriter(new FileWriter(arquivo,append))) { | |
| bw.append(conteudo + "\n"); | |
| bw.close(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public void REescrever(String arquivo, String conteudo) { | |
| boolean append = false; | |
| try (BufferedWriter bw = new BufferedWriter(new FileWriter(arquivo,append))) { | |
| bw.append(conteudo + "\n"); | |
| bw.close(); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| public void esperar(int segundos) { | |
| try { | |
| Thread.sleep(segundos * 1000); | |
| } catch(InterruptedException ex) | |
| { | |
| Thread.currentThread().interrupt(); | |
| } | |
| } | |
| public boolean se_arquivo_existe(String arquivo) { | |
| Path p = Paths.get(arquivo); | |
| boolean exists = Files.exists(p); | |
| return exists; | |
| } | |
| public void verificar_se_pagina_foi_carregada(String algum_texto_a_ser_encontrado_na_pagina) { | |
| cb _cb = new cb(); | |
| copiar_tudo(); | |
| String clipp = _cb.colado(); | |
| while( clipp.indexOf(algum_texto_a_ser_encontrado_na_pagina) == -1 ) { | |
| esperar(1); | |
| copiar_tudo(); | |
| clipp = _cb.colado(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment