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 a1f87c3b57c96025a0f2f849f1f8e79f1cd4671e
parent 4350bf9ca7d660059eebbac26a0b8e8449d94c81
Author: Ilyass Sfar <42755577+cloud0x9@users.noreply.github.com>
Date:   Sun,  9 Feb 2020 22:07:13 -0500

Merge pull request #1 from wrycode/maven-setup

Maven setup
Diffstat:
DSchedueData/DataController.java | 12------------
DSchedueData/GetData.java | 57---------------------------------------------------------
DSchedueData/ParseData.java | 43-------------------------------------------
DSchedueData/SaveData.java | 44--------------------------------------------
Apom.xml | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/main/java/ScheduleCreator/DataController.java | 12++++++++++++
Asrc/main/java/ScheduleCreator/GetData.java | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/main/java/ScheduleCreator/ParseData.java | 41+++++++++++++++++++++++++++++++++++++++++
Asrc/main/java/ScheduleCreator/SaveData.java | 44++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 240 insertions(+), 156 deletions(-)

diff --git a/SchedueData/DataController.java b/SchedueData/DataController.java @@ -1,12 +0,0 @@ -package SchedueData; -//run this -import java.io.IOException; -//not really a Controller yet, but just a holder for now -public class DataController { - - public static void main(String[] args) throws IOException { - - // -SchedueData.ParseData.String(); - - }} diff --git a/SchedueData/GetData.java b/SchedueData/GetData.java @@ -1,57 +0,0 @@ -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/SchedueData/ParseData.java b/SchedueData/ParseData.java @@ -1,43 +0,0 @@ -package SchedueData; - -import java.io.*; -import java.util.regex.*; - - - -public class ParseData { - - static void String() throws IOException { - - //Hard code example, 2 is 2020, and 22 is CSC on the uncg webiste - 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 - ("[0-9]{5}|\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"); - - //("\\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 - 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)); - - - } - } - } -} diff --git a/SchedueData/SaveData.java b/SchedueData/SaveData.java @@ -1,43 +0,0 @@ -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 diff --git a/pom.xml b/pom.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>ScheduleCreator</groupId> + <artifactId>Schedule-creator</artifactId> + <version>1.0-SNAPSHOT</version> + + <name>Schedule-creator</name> + <!-- FIXME change it to the project's website --> + <url>http://www.example.com</url> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.source>1.7</maven.compiler.source> + <maven.compiler.target>1.7</maven.compiler.target> + </properties> + + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + <version>3.141.59</version> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>htmlunit-driver</artifactId> + <version>2.33.2</version> + </dependency> + </dependencies> + + <build> + <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> + <plugins> + <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <version>3.1.0</version> + </plugin> + <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.1</version> + </plugin> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <version>2.5.2</version> + </plugin> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.2</version> + </plugin> + <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <version>3.7.1</version> + </plugin> + <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>3.0.0</version> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> diff --git a/src/main/java/ScheduleCreator/DataController.java b/src/main/java/ScheduleCreator/DataController.java @@ -0,0 +1,12 @@ +package ScheduleCreator; +//run this +import java.io.IOException; +//not really a Controller yet, but just a holder for now +public class DataController { + + public static void main(String[] args) throws IOException { + + // +ScheduleCreator.ParseData.String(); + + }} diff --git a/src/main/java/ScheduleCreator/GetData.java b/src/main/java/ScheduleCreator/GetData.java @@ -0,0 +1,57 @@ +package ScheduleCreator; + +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; + } + +} + + + + + \ No newline at end of file diff --git a/src/main/java/ScheduleCreator/ParseData.java b/src/main/java/ScheduleCreator/ParseData.java @@ -0,0 +1,41 @@ +package ScheduleCreator; + +import java.io.*; +import java.util.regex.*; + +public class ParseData { + + static void String() throws IOException { + + //Hard code example, 2 is 2020, and 22 is CSC on the uncg webiste + FileWriter FileW = ScheduleCreator.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 + ("[0-9]{5}|\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"); + + //("\\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 + 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)); + + + } + } + } +} diff --git a/src/main/java/ScheduleCreator/SaveData.java b/src/main/java/ScheduleCreator/SaveData.java @@ -0,0 +1,43 @@ +package ScheduleCreator; +//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 = ScheduleCreator.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