Skip to content

Commit

Permalink
Merge pull request #30 from AlbertLin1102/master
Browse files Browse the repository at this point in the history
fixed issue #21 & #27
  • Loading branch information
SElegans committed Nov 14, 2016
2 parents 3ea3d9d + 87482b7 commit b0faafe
Show file tree
Hide file tree
Showing 9 changed files with 467 additions and 277 deletions.
11 changes: 7 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
<!-- Significant change/reformat build.xml for Github, W15, CS56
name: Brent Kirkland, Dylan Lynch -->

<!-- Change build.xml for Github, F16, CS56
name: Jeremy You, Xingyuan Lin -->

<property environment="env"/> <!-- load the environment variables -->
<property name="webRoot" value="${env.HOME}/public_html/"/>
<property name="webBaseUrl" value="http://www.cs.ucsb.edu/~${env.USER}"/>

<property name="course" value="cs56"/>
<property name="quarter" value="W15"/>
<property name="projectName" value="GEscraper"/>
<property name="mainClass" value="edu.ucsb.cs56.W15.GEscraper.GEscraper"/>
<property name="quarter" value="F16"/>
<property name="projectName" value="CourseScraper"/>
<property name="mainClass" value="edu.ucsb.cs56.F16.CourseScraper.CourseScraper"/>
<property name="projectPath" value="${course}/${quarter}/${projectName}"/>

<property name="javadocDest" value="${webRoot}/${projectName}/javadoc"/>
Expand All @@ -35,7 +38,7 @@
</target>

<!-- Run the scraper -->
<target name="run" depends="compile, jar" description="run the GEscraper">
<target name="run" depends="compile, jar" description="run the CourseScraper">
<java fork="true" classname="${mainClass}">
<classpath refid="project.class.path"/>
</java>
Expand Down
Binary file added dist/cs56_F16_CourseScraper.jar
Binary file not shown.
Binary file modified dist/cs56_W15_GEscraper.jar
Binary file not shown.
131 changes: 131 additions & 0 deletions src/edu/ucsb/cs56/F16/CoursesScraper/CourseScraper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package edu.ucsb.cs56.F16.CourseScraper;

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.Scanner;

/** GEscraper Class takes classes from a URL and displays them in a list.
@author Brent Kirkland
@author Dylan Lynch
@version 03.04.15
*/

public class CourseScraper {
//main
public static void main(String args[]){
boolean loop = true;
ArrayList<String> list = new ArrayList<String>();
String area, department;
GetGeInfo getgeinfo = new GetGeInfo();
while (loop == true) {

Scanner areaScanner = new Scanner(System.in);
Scanner departmentScanner = new Scanner(System.in);

Object[] options = {"Engineering",
"General Subject"};
int engrOrGe = JOptionPane.showOptionDialog(null,
"choose to display courses from engineering or general subject",
"Menu",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if(engrOrGe==JOptionPane.YES_OPTION){
String[] departments={"Chemical Engineering","Computer Engineering", "Computer Science - Engineering", "Electrical and Computer Engineering", "Engineering Sciences", "Materials", "Mechanical Engineering", "Technology Management Program"};
department = (String) JOptionPane.showInputDialog(null, "Enter a Department Name:", "Menu", JOptionPane.QUESTION_MESSAGE, null, departments, departments[0]);
String dept = "";
switch(department){
case "Chemical Engineering": dept = "chemengr";break;
case "Computer Engineering": dept = "compengr";break;
case "Computer Science - Engineering": dept = "compsci-engr";break;
case "Electrical and Computer Engineering": dept = "ece";break;
case "Engineering Sciences": dept = "engrsci";break;
case "Materials": dept = "matrl";break;
case "Mechanical Engineering": dept = "mechengr";break;
case "Technology Management Program": dept = "tmp";break;
}
ArrayList<String> courses = GetEngInfo.getCourses(dept);
JFrame f = new JFrame("RESULTS");
f.setSize(400, 800);

String[] data = courses.toArray(new String[courses.size()]);
f.add(new JScrollPane(new JList(data)));

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);

System.out.println("Scrape? Y/N");
area = areaScanner.next();
if (area.equals("N")) { loop = false; }
}
else if(engrOrGe==JOptionPane.NO_OPTION){
//System.out.println("Enter a Subject Area (B-H or WRT, EUR, NWC, QNT, ETH) or enter HELP for a list of all areas and courses");
//area = areaScanner.next();
String[] choices={"B", "C", "D", "E", "F", "G", "H", "WRT", "EUR", "QNT", "NWC", "ETH"};
// JOptionPane: pop up a standard dialog box
area = (String) JOptionPane.showInputDialog(null, "Enter a Subject Area:", "Menu", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
System.out.println(area);

if (area.equals("HELP")) {
System.out.println("General/Special Subject Area Inputs:");
System.out.println("Input = Course List Result");
System.out.println("Area B Courses = B");
System.out.println("Area C Courses = C");
System.out.println("Area D Courses = D");
System.out.println("Area E Courses = E");
System.out.println("Area F Courses = F");
System.out.println("Area G Courses = G");
System.out.println("Area H Courses = H");
System.out.println("Writing Courses = WRT");
System.out.println("European Courses = EUR");
System.out.println("World Cultures Courses = NWC");
System.out.println("Quantitative Courses = QNT");
System.out.println("Ethnicity Courses = ETH");

ArrayList<ArrayList<String>> departments = getgeinfo.getDepartments();
ArrayList<String> departmentt;
for (int i = 0; i < departments.size(); i++) {
departmentt = departments.get(i);
System.out.println(departmentt.get(0) + " = " + departmentt.get(1));
}
//System.out.println("Enter a Subject Area: ");
//area = areaScanner.next();
}

//System.out.println("Enter a specific department abbrevation or N (No): ");
department = (String) JOptionPane.showInputDialog("Enter a specific department abbrevation or N (No): ");
//department = departmentScanner.next();
if (department.equals("N")) {
list = getgeinfo.getCourses(area);
}
else {
list = getgeinfo.getSpecificCourses(area, department);
}

//for(int i=0; i<list.size(); i++){ System.out.println(list.get(i)); }
JFrame f = new JFrame("RESULTS");
f.setSize(400, 800);

String[] data = list.toArray(new String[list.size()]);
f.add(new JScrollPane(new JList(data)));

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocationRelativeTo(null);
f.setVisible(true);

System.out.println("Scrape? Y/N");
area = areaScanner.next();
if (area.equals("N")) { loop = false; }
}
}
}//end main

}//end GEscraper
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package edu.ucsb.cs56.W15.GEscraper;
package edu.ucsb.cs56.F16.CourseScraper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.*;
import java.io.*;
import java.net.*;


/** test class for GEscraper
/** test class for CoursesScraper
@author Brian Wan
@author Dylan Lynch
@version 03.04.15
@see GEscraper
@see CoursesScraper
*/

public class GEscraperTest {
public class CourseScraperTest {

/** Test getSpecificCourses with General Course Input
@see GEscraper
@see CoursesScraper
*/
@Test
public void test_getSpecificCourses() {
GEscraper g = new GEscraper();
// ArrayList with only Area B French courses
ArrayList<String> f = g.getSpecificCourses("B", "FR");
// ArrayList with all Area B Courses
ArrayList<String> a = g.getCourses("B");
System.out.println("getCourses: " + a.get(7));
System.out.println("getSpecificCourses: " + f.get(0));
assertEquals(f.get(0), a.get(7));
// GetInfo g = new GetInfo();
// // ArrayList with only Area B French courses
// ArrayList<String> f = g.getSpecificCourses("B", "FR");
// // ArrayList with all Area B Courses
// ArrayList<String> a = g.getCourses("B");
// System.out.println("getCourses: " + a.get(7));
// System.out.println("getSpecificCourses: " + f.get(0));
// assertEquals(f.get(0), a.get(7));
}

// /** Test getCourses with General Course Input
// @see GEscraper
// @see CoursesScraper
// */
// @Test
// public void test_getCoursesGeneral(){
// GEscraper g = new GEscraper();
// CoursesScraper g = new CoursesScraper();
// ArrayList<String> s = g.getCourses("B");

// String a = s.get(0);
// assertEquals(a, b);
// }

// * Test getCourses with Special Course Subject Input"
// @see GEscraper
// @see CoursesScraper

// @Test
// public void test_getCoursesSpecial(){
// GEscraper g = new GEscraper();
// CoursesScraper g = new CoursesScraper();
// ArrayList<String> s = g.getCourses("QNT");

// String a = s.get(0);
Expand Down
118 changes: 118 additions & 0 deletions src/edu/ucsb/cs56/F16/CoursesScraper/GetEngInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package edu.ucsb.cs56.F16.CourseScraper;

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.Scanner;

/** GEscraper Class takes classes from a URL and displays them in a list.
@author Brent Kirkland
@author Dylan Lynch
@version 03.04.15
*/

public class GetEngInfo {


public static final String urlPrefix = "https://my.sa.ucsb.edu/catalog/Current/CollegesDepartments/coe/";
public static final String urlSuffix = ".aspx?DeptTab=Courses";

/** create specific url for area of general ed
@param Specific area "B", "C", "D", "E", "F", "G", "H"
@return url for specified general area courses
*/
private static String getDeptCoursesURL(String dept) {
String url = urlPrefix + dept + urlSuffix;
return url;
}

/** Get all departments for ease searching
@return Arraylist of ArrayList holding the course acronym and course name
*/
// public static ArrayList<String> getDepartments(){

// String url = "https://my.sa.ucsb.edu/catalog/Current/CollegesDepartments/coe/AcademicDepartments.aspx";


// ArrayList<String> outer = new ArrayList<String>();

// try {
// Document doc = Jsoup.connect(url).get();
// Element departments = doc.getElementById("ctl00_ctl00_iisChildren_itemsInSectionContainer");
// Elements dept_list = departments.getElementsByTag("a");
// for(Element e : dept_list){
// outer.add(e.html());
// }

// } catch(MalformedURLException e) {
// System.out.println("Seems like the subject URL has moved");
// System.exit(1);

// } catch(IOException e){
// System.out.println("Check yo internet yo!");

// }
// return outer;
// }

/** get course numbers of gen/special subject courses in a given area
@param area as B->H or Special Subject Abbreviation: "WRT", "EUR", "NWC", "QNT", "ETH"
@return array list of all courses with { Course Abbreviation, Course Number, Full Course Name }
*/
public static ArrayList<String> getCourses(String area) {

// Check if Gen Ed Course or Special Subject Ed Course
String url = getDeptCoursesURL(area);

//create an ArrayList to store courses
ArrayList<String> courses = new ArrayList<String>();

//JSOUP Version
Document doc=Jsoup.parse("");
try{
doc = Jsoup.connect(url).get();
}
//Catch bad URL
catch (MalformedURLException e) {
System.out.println("Area does not exist.");
System.exit(1);
}
//catch IOException
catch (IOException e) {
System.out.println("Check Internet.");
System.exit(1);
}

Element container = doc.getElementById("ctl00_ctl00_ContentPlaceHolder1_ctl00_divLowerDivision");
Elements course_list = container.getElementsByTag("b");
for(int i = 0; i < course_list.size(); i += 2){
courses.add(course_list.get(i).html());
}

Element containerupper = doc.getElementById("ctl00_ctl00_ContentPlaceHolder1_ctl00_divUpperDivision");
Element containergrad = doc.getElementById("ctl00_ctl00_ContentPlaceHolder1_ctl00_divGrad");
Elements course_list2 = containerupper.getElementsByTag("b");
Elements course_list_grad = containergrad.getElementsByTag("b");
course_list2.addAll(course_list_grad);
String tmp = "";
for(int i = 0; i < course_list2.size(); i ++){
Element e = course_list2.get(i);
// tmp = e.html();
tmp=e.html().replaceAll("<span class=\"CourseIdAndTitle\"> ", "");
tmp=tmp.replaceAll("<span class=\"CourseFullTitle\" name=\"CourseDisplay\">", "");
tmp=tmp.replaceAll("</span>", "");
tmp=tmp.replaceAll("<span class=\"CourseFullTitle\" name=\"CourseChildDisplay\">","");
courses.add(tmp);
}

return courses;
}



}//end GetInfo

0 comments on commit b0faafe

Please sign in to comment.