Created
November 1, 2016 22:15
-
-
Save tarunbod/edbcf2964cd75da9125231d9bf914aaf to your computer and use it in GitHub Desktop.
Check your grades for parent portal
This file contains 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 me.tarunb.gradechecker; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.phantomjs.PhantomJSDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
import java.io.File; | |
import java.io.PrintStream; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Main { | |
public static void main(String[] args) { | |
// ignore stupid error messages | |
try { | |
File errFile = new File("err.out"); | |
System.setErr(new PrintStream(errFile)); | |
errFile.deleteOnExit(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
List<String> classNames = new ArrayList<>(); | |
List<Double> grades = new ArrayList<>(); | |
System.out.println("Fetching grades..."); | |
long start = System.currentTimeMillis(); | |
PhantomJSDriver driver = new PhantomJSDriver(); | |
driver.get("https://parents.edison.k12.nj.us/genesis/parents?gohome=true"); | |
driver.findElementById("j_username").sendKeys("YOUR_EMAIL_HERE"); | |
driver.findElementById("j_password").sendKeys("YOUR_PASSWORD_HERE"); | |
driver.findElementByClassName("saveButton").click(); | |
WebDriverWait gradeWait = new WebDriverWait(driver, 3); | |
gradeWait.until(ExpectedConditions.presenceOfElementLocated(By.className("list"))); | |
List<WebElement> classElems = driver.findElementsByClassName("categorytab"); | |
classElems.forEach(elem -> classNames.add(elem.findElement(By.tagName("u")).getText())); | |
List<WebElement> gradeElems = driver.findElements(By.cssSelector(".cellRight[width=\"70%\"]")); | |
gradeElems.forEach(elem -> grades.add(Double.parseDouble(elem.getText().replace("%", "")))); | |
long end = System.currentTimeMillis(); | |
System.out.println("Fetched grades in " + ((end - start) / 1000.0) + " seconds:"); | |
int longestClassNameLength = classNames.stream().map(String::length).sorted((o1, o2) -> o2 - o1).findFirst().get(); | |
for (int i = 0; i < classNames.size(); i++) { | |
double currentGrade = grades.get(i); | |
System.out.printf("%-" + longestClassNameLength + "s : %6.2f (%s)\n", classNames.get(i), currentGrade, getLetterGrade(currentGrade)); | |
} | |
driver.quit(); | |
} | |
private static String getLetterGrade(double num) { | |
if (num >= 96.5) { | |
return "A+"; | |
} else if (num >= 92.5) { | |
return "A"; | |
} else if (num >= 89.5) { | |
return "A-"; | |
} else if (num >= 86.5) { | |
return "B+"; | |
} else if (num >= 82.5) { | |
return "B"; | |
} else if (num >= 79.5) { | |
return "B-"; | |
} else if (num >= 76.5) { | |
return "C+"; | |
} else if (num >= 72.5) { | |
return "C"; | |
} else if (num >= 69.5) { | |
return "C-"; | |
} else { | |
return "you're doing really bad"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment