-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from AlbertLin1102/master
- Loading branch information
Showing
9 changed files
with
467 additions
and
277 deletions.
There are no files selected for viewing
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
Binary file not shown.
Binary file not shown.
131 changes: 131 additions & 0 deletions
131
src/edu/ucsb/cs56/F16/CoursesScraper/CourseScraper.java
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
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 |
34 changes: 17 additions & 17 deletions
34
...csb/cs56/W15/GEscraper/GEscraperTest.java → ...F16/CoursesScraper/CourseScraperTest.java
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
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
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 | ||
|
Oops, something went wrong.