Last active
August 29, 2015 14:10
-
-
Save gledhil8/554a585e8bc3739475f1 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
import java.util.*; | |
import javax.swing.JFrame; | |
import javax.swing.JOptionPane; | |
import javax.activation.*; | |
import java.awt.Toolkit; | |
import java.io.BufferedReader; | |
import java.io.BufferedWriter; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.FileWriter; | |
import java.io.IOException; | |
import java.io.PrintStream; | |
import java.io.PrintWriter; | |
import java.io.UnsupportedEncodingException; | |
import java.net.MalformedURLException; | |
import java.util.ArrayList; | |
import com.gargoylesoftware.htmlunit.BrowserVersion; | |
import com.gargoylesoftware.htmlunit.WebClient; | |
import com.gargoylesoftware.htmlunit.html.HtmlAnchor; | |
import com.gargoylesoftware.htmlunit.html.HtmlButton; | |
import com.gargoylesoftware.htmlunit.html.HtmlElement; | |
import com.gargoylesoftware.htmlunit.html.HtmlInput; | |
import com.gargoylesoftware.htmlunit.html.HtmlPage; | |
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; | |
@SuppressWarnings("all") | |
public class rosi { | |
private static ArrayList<String> CompareFile(String file1, String file2) | |
throws Exception { | |
File f1 = new File(file1); | |
File f2 = new File(file2); | |
FileReader fR1 = new FileReader(f1); | |
FileReader fR2 = new FileReader(f2); | |
BufferedReader reader1 = new BufferedReader(fR1); | |
BufferedReader reader2 = new BufferedReader(fR2); | |
String line1 = null; | |
String line2 = null; | |
Boolean same = true; | |
ArrayList<String> dif = new ArrayList<String>(); | |
while (((line1 = reader1.readLine()) != null) | |
&&((line2 = reader2.readLine()) != null)) { | |
if (!line1.equalsIgnoreCase(line2)) { | |
same = false; | |
dif.add(line2); | |
} | |
} | |
reader1.close(); | |
reader2.close(); | |
return dif; | |
} | |
public static void main(String[] args)throws Exception | |
{ | |
System.setErr(new PrintStream("/dev/null")); | |
Scanner keyboard = new Scanner(System.in); | |
System.out.println("Enter Student number"); | |
int studentNumberInput = keyboard.nextInt(); | |
System.out.println(studentNumberInput); | |
keyboard = new Scanner(System.in); | |
System.out.println("Password"); | |
int passwordInput = keyboard.nextInt(); | |
System.out.println(passwordInput); | |
int count =1; | |
keyboard.close(); | |
while (1==1){ | |
System.out.println("Check # "+count); | |
final WebClient webClient = new WebClient(BrowserVersion.CHROME); | |
webClient.getOptions().setJavaScriptEnabled(false); | |
//to get to login page | |
HtmlPage page1 = webClient.getPage("http://www.rosi.utoronto.ca/"); | |
//final HtmlAnchor anchor = page1.getAnchorByName("secondary-btn secondary-btn-large btn-secondary"); | |
HtmlAnchor anchor =page1.getAnchorByText("Login to ROSI"); | |
page1=anchor.click(); | |
//login page | |
HtmlInput studentNumber = page1.getHtmlElementById("personId"); | |
studentNumber.setValueAttribute(Integer.toString(studentNumberInput)); | |
HtmlInput password = page1.getHtmlElementById("pin"); | |
password.setValueAttribute(Integer.toString(passwordInput)); | |
HtmlSubmitInput button = (HtmlSubmitInput) page1.getByXPath("/html/body//form//input[@type='submit' and @value='Login']").get(0); | |
page1=button.click(); | |
//navigate to marks | |
HtmlAnchor anchor2 =page1.getAnchorByText("Transcripts, Academic History"); | |
try{ | |
page1=anchor2.click(); | |
} | |
catch (Exception e){ | |
System.out.println(e); | |
} | |
File file = new File("Rosi_Filter_local_marks.txt"); | |
if(file.exists()) { | |
try { | |
BufferedWriter output = new BufferedWriter(new FileWriter("Rosi_Filter_local_marks2.txt")); | |
output.write(page1.asText()); | |
output.close(); | |
ArrayList<String> dif = CompareFile("Rosi_Filter_local_marks.txt", "Rosi_Filter_local_marks2.txt"); | |
if (dif.size()> 0){ | |
for (int i = 0; i < dif.size(); i++){ | |
String item = dif.get(i); | |
System.out.println("Item " + i + " : " + item); | |
JFrame j=new JFrame(); | |
j.setAlwaysOnTop(true); | |
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
j.setVisible(true); | |
j.setVisible(false); | |
JOptionPane.showMessageDialog(j,"NEW MARKS" + item); | |
} | |
System.out.println("done"); | |
} | |
try { | |
output = new BufferedWriter(new FileWriter(file)); | |
output.write(page1.asText()); | |
output.close(); | |
} catch ( IOException e ) { | |
e.printStackTrace(); | |
} | |
} catch ( IOException e ) { | |
e.printStackTrace(); | |
} | |
} | |
else{ | |
try { | |
BufferedWriter output = new BufferedWriter(new FileWriter(file)); | |
output.write(page1.asText()); | |
output.close(); | |
} catch ( IOException e ) { | |
e.printStackTrace(); | |
} | |
} | |
Thread.sleep(2000); | |
webClient.closeAllWindows(); | |
count = count +1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment