Schedule-Creator

Java GUI to create schedules for UNCG students
git clone git://git.wrycode.com/wrycode/archive/Schedule-Creator.git
Log | Files | Refs | README

commit 61363e7c2bbe92f321163b5990d9e49fcbe978bd
parent ee2f68035c2eefe57bd5870803c1f806a3f18c04
Author: Ilyass Sfar <42755577+cloud0x9@users.noreply.github.com>
Date:   Wed,  5 Feb 2020 19:43:18 -0500

Add files via upload
Diffstat:
Asrc/SchedueData/DataController.java | 12++++++++++++
Asrc/SchedueData/GetData.java | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/SchedueData/ParseData.java | 43+++++++++++++++++++++++++++++++++++++++++++
Asrc/SchedueData/SaveData.java | 44++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/src/SchedueData/DataController.java b/src/SchedueData/DataController.java @@ -0,0 +1,11 @@ +package SchedueData; + +import java.io.IOException; + +public class DataController { + + public static void main(String[] args) throws IOException { + +SchedueData.ParseData.String(); + + }}+ \ No newline at end of file diff --git a/src/SchedueData/GetData.java b/src/SchedueData/GetData.java @@ -0,0 +1,57 @@ +package SchedueData; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.openqa.selenium.support.ui.Select; + +public class GetData { + + /** + * + * @param Semester - currently uses a index to select from a dropdown menu on the website + * @param Department - is a placeholder for Department of the class being searched + */ + static String GetDataMethod(int Semester, int Department){ + //turn off anoying warning messages + java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF); + java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF); + //Creating a new instance of the HTML unit driv + WebDriver driver = new HtmlUnitDriver(); + //Go to base uncg banner webiste, since starting anywhere else causes errors + driver.get("https://ssb.uncg.edu/"); + //click on "Detailed Class Schedule" to go to class sherch engine + WebElement linkByText = driver.findElement(By.xpath("/html/body/div[3]/table[1]/tbody/tr[7]/td[2]/a")); + linkByText.click(); + //click on dropdown menu to choose semester - "p_term" is the html name of the semester dropbox menu on the webiste + WebElement DropDown = driver.findElement(By.name("p_term")); + Select dropdown = new Select(DropDown); + ///////Everything above this point is always the same no matter the search being done///////////////// + + + //click on options from dropdown menu using an index to make things easier + dropdown.selectByIndex(Semester); + //click on submit key at bottom of the slect term page + DropDown.submit(); + //Find the subject table + WebElement table = driver.findElement(By.xpath("/html/body/div[3]/form/table[1]/tbody/tr/td[2]")); + //select CSC option from the subject table + WebElement Subject = table.findElement(By.xpath("//*[@id=\"subj_id\"]/option["+ Department+ "]")); + + Subject.click(); + Subject.submit(); + + //on the results page print all tables that appear, used to easily test if this method actaully works + //System.out.println(driver.findElement(By.className("datadisplaytable")).getText()); + + String WebData = driver.findElement(By.className("datadisplaytable")).getText(); + driver.quit(); + return WebData; + } + +} + + + + diff --git a/src/SchedueData/ParseData.java b/src/SchedueData/ParseData.java @@ -0,0 +1,42 @@ +package SchedueData; + +import java.io.*; +import java.util.regex.*; + + + +public class ParseData { + + static void String() throws IOException { + + + FileWriter FileW = SchedueData.SaveData.WriteFile("TestFile.txt",2,22); + BufferedWriter BufferW = new BufferedWriter(FileW); + + //this it the regex expression it grabs abbreviated class name with section, time, and day of the class + // ex. CSC 340-01, 5:30-6:45, T H (days) + Pattern regex = Pattern.compile + ("\\b[A-Z]{3}\\b.\\b[0-9]{3}\\b.* [0-9]{2}\\b|([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]|([AaPp][Mm])\\b|TR\\b|MW\\b|MWF\\b|M\\b|T\\b|W\\b|R\\b|F\\b/g"); + + // ("\b[A-Z]{3}\b.\b[0-9]{3}\b.* [0-9]{2}\b|([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]|([AaPp][Mm])\b|TR\b|MW\b|MWF\b|M\b|T\b|W\b|R\b|F\b/g"); + // A FileReader (see the I/O chapter) + BufferedReader r = new BufferedReader(new FileReader("TestFile.txt")); + + // matching lines with regex expression + String line; + while ((line = r.readLine()) != null) { + // find lines that match + Matcher regexMatcher = regex.matcher(line); + while (regexMatcher.find()) { + // Get the starting position of the text + int start = regexMatcher.start(0); + // Get ending position + int end = regexMatcher.end(0); + // Print whatever matched. + System.out.println(line.substring( start, end)); + + + } + } + } +}+ \ No newline at end of file diff --git a/src/SchedueData/SaveData.java b/src/SchedueData/SaveData.java @@ -0,0 +1,43 @@ +package SchedueData; +//creates a text file and writes the results from the original web search + +import java.io.*; + + +public class SaveData { + + static FileWriter WriteFile(String Name, int Sem, int Dep){ + + // Create new file, write all results into the file + try{ + String content = SchedueData.GetData.GetDataMethod(Sem, Dep); + String path = Name; + File file = new File(path); + + // If file doesn't exists, then create it + if (!file.exists()) { + file.createNewFile(); + } + FileWriter FileW = new FileWriter(file.getAbsoluteFile()); + BufferedWriter BufferW = new BufferedWriter(FileW); + + // Write in file + BufferW.write(content); + + // Close connection + BufferW.close(); + + return FileW; + + } + //Exception filler + catch(Exception X){ + System.out.println(X); + } + + + return null; + + } + +}+ \ No newline at end of file