Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a library in python that will contain two methods that will aid students i

ID: 3683339 • Letter: W

Question

Write a library in python that will contain two methods that will aid students in finding information about classes.

These methods will all need to read from our online custom interface. For example, if you want to see all the courses in the CS department, can go to:

http://goo.gl/Tggqtb

and you’ll see many lines like

if you view the source of the page (Chrome: View->Developer->View Source and Firefox: Tools->Web Developer->Page Source).

By replacing the text after the last / with any department at UVa, you can see their classes! For example, BIOL will load all Biology classes.

For each line on the page, the fields are (in order):

Dept ID (0)

Course Number (1)

Section (2)

Course Title (3)

Instructor (4)

Type of class (5)

Hours (6)

Monday (7)

Tuesday (8)

Wednesday (9)

Thursday (10)

Friday (11)

Start Time (12)

End Time (13)

Location (14)

Enrollment (15)

Allowable Enrollment (16)

Latitude (17)

Longitude (18)

Start and end times are expressed in the CSV as a 3- or 4-character string representing a 24-hour clock so, e.g., CS 1112 starts at 1400 and ends at 1515, for a duration of 75 minutes and CS 2150 section 105 starts at 1330 and ends at 1515 for a duration of 105 minutes.

Some sections have a listed start and end time of -1, meaning they do not have a fixed schedule.

instructors(department): Returns a sorted list containing each instructor listed in Lou’s List for the given department. Do not count the same instructor twice. For example, Mark Sherriff is listed as instructor for around 19 courses for the CS department but should only appear in the resulting list once.

To test this function, you should create a separate testing file. If you invoke instructors("EAST") you should get back a list with three elements: [‘Benedetta Lomi’, ‘Michiko Wilson’, ‘Staff’]. Note that the order does matter here. If you invoke instructors("URDU") you should get back a list with one element: [‘Griffith Chaussee’].

class_search(dept_name, has_seats_available=True, level=None, not_before=None, not_after=None): Returns a list of lists which contains all the information for all the classes that meet the provided criteria.

By default, if you invoke class_search("CS"), the function should return a list containing all of the information from all of the CS courses in which there are seats available (Enrollment < Allowable Enrollment). If you invoke class_search("CS", False), then all classes should be displayed, regardless of enrollment. As you add the optional parameters, you can adjust the search even more.

has_seats_available - If set to True, the function will check to ensure that Enrollment is not greater than or equal to Allowable Enrollment (i.e. there are seats actually available for a student to take). If set to False then it doesn’t matter if there are seats available or not and current enrollment should be ignored when determining if the class should be returned or not.

level - Given a 4-digit level value, the function should only include classes that are at that level. For example, saying level=2000 should limit the list to only courses whose first digit is 2.

not_before - Tells the function to exclude all classes that start before (but not at) that time. For example, if you say not_before=1000, then the function should exclude 9:00 and 9:30 classes, but still include 10:00 classes.

not_after - Tells the function to exclude all classes that start after (but not at) that time. For example, if you say not_after=1400, then the function should exclude classes that start at 3:00, but not 2:00.

For example, if you invoke class_search("CS", level=1000, not_before=1600) it should return (example formatted to make it easier to read):

  1  
  CS;1110;001;Introduction to Programming;Mark Sherriff;Lecture;3;true;false;true;false;true;1100;1150;Rice Hall 130;148;147;38.031639;-78.510811  

if you view the source of the page (Chrome: View->Developer->View Source and Firefox: Tools->Web Developer->Page Source).

By replacing the text after the last / with any department at UVa, you can see their classes! For example, BIOL will load all Biology classes.

For each line on the page, the fields are (in order):

Dept ID (0)

Course Number (1)

Section (2)

Course Title (3)

Instructor (4)

Type of class (5)

Hours (6)

Monday (7)

Tuesday (8)

Wednesday (9)

Thursday (10)

Friday (11)

Start Time (12)

End Time (13)

Location (14)

Enrollment (15)

Allowable Enrollment (16)

Latitude (17)

Longitude (18)

Start and end times are expressed in the CSV as a 3- or 4-character string representing a 24-hour clock so, e.g., CS 1112 starts at 1400 and ends at 1515, for a duration of 75 minutes and CS 2150 section 105 starts at 1330 and ends at 1515 for a duration of 105 minutes.

Some sections have a listed start and end time of -1, meaning they do not have a fixed schedule.

instructors(department): Returns a sorted list containing each instructor listed in Lou’s List for the given department. Do not count the same instructor twice. For example, Mark Sherriff is listed as instructor for around 19 courses for the CS department but should only appear in the resulting list once.

To test this function, you should create a separate testing file. If you invoke instructors("EAST") you should get back a list with three elements: [‘Benedetta Lomi’, ‘Michiko Wilson’, ‘Staff’]. Note that the order does matter here. If you invoke instructors("URDU") you should get back a list with one element: [‘Griffith Chaussee’].

class_search(dept_name, has_seats_available=True, level=None, not_before=None, not_after=None): Returns a list of lists which contains all the information for all the classes that meet the provided criteria.

By default, if you invoke class_search("CS"), the function should return a list containing all of the information from all of the CS courses in which there are seats available (Enrollment < Allowable Enrollment). If you invoke class_search("CS", False), then all classes should be displayed, regardless of enrollment. As you add the optional parameters, you can adjust the search even more.

has_seats_available - If set to True, the function will check to ensure that Enrollment is not greater than or equal to Allowable Enrollment (i.e. there are seats actually available for a student to take). If set to False then it doesn’t matter if there are seats available or not and current enrollment should be ignored when determining if the class should be returned or not.

level - Given a 4-digit level value, the function should only include classes that are at that level. For example, saying level=2000 should limit the list to only courses whose first digit is 2.

not_before - Tells the function to exclude all classes that start before (but not at) that time. For example, if you say not_before=1000, then the function should exclude 9:00 and 9:30 classes, but still include 10:00 classes.

not_after - Tells the function to exclude all classes that start after (but not at) that time. For example, if you say not_after=1400, then the function should exclude classes that start at 3:00, but not 2:00.

For example, if you invoke class_search("CS", level=1000, not_before=1600) it should return (example formatted to make it easier to read):

  12345  
  [     ['CS', '1110', '106', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '3', 'false', 'false', 'false', 'true', 'false', '1700', '1815', 'Olsson Hall 001', '0', '44', '38.032079', '-78.510755'],      ['CS', '1110', '107', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '3', 'false', 'false', 'false', 'true', 'false', '1830', '1945', 'Olsson Hall 001', '0', '44', '38.032079', '-78.510755'],      ['CS', '1110', '108', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '3', 'false', 'false', 'false', 'true', 'false', '2000', '2115', 'Olsson Hall 001', '0', '44', '38.032079', '-78.510755']  ]  

Explanation / Answer

import urllib.request

def instructors(department):
    pagename = "http://stardock.cs.virginia.edu/louslist/Courses/view/" + department
    courses = urllib.request.urlopen(pagename)
    professors = []
    for course in courses:
        if not course.decode("UTF-8").split(";")[4] in professors:
            professors.append(course.decode("UTF-8").split(";")[4])
    return sorted(professors)
def class_search(dept_name, has_seats_available=True, level=None, not_before=None, not_after=None):
    pagename = "http://stardock.cs.virginia.edu/louslist/Courses/view/" + dept_name
    allcourses = urllib.request.urlopen(pagename)
    courses = []
    for course in allcourses:
        course_info = course.decode("UTF-8").strip().split(";")
        if has_seats_available is True:
            if course_info[15] > course_info[16]:
                continue
        if level != None:
            if course_info[1][0] != str(level)[0]:
                continue
        if not_before != None:
            if int(course_info[12]) < not_before:
                continue
        if not_after != None:
            if int(course_info[13]) > not_after:
                continue
        courses.append(course_info)
    return courses

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote