Esempio n. 1
0
    def gen_folder(self, unit): #unit corresponds to a folder
        folder_dict = {}
        unit.find_element_by_tag_name('a').click() # clicking 'Additional Practice problems'
        if self.check_id_exists('content_listContainer'):
            num_of_items = len(self.browser.find_element_by_id('content_listContainer').find_elements_by_tag_name('li'))
            for unit_index in range(num_of_items):
                inner_unit = self.browser.find_element_by_id('content_listContainer').find_elements_by_tag_name('li')[unit_index]
                if self.check_tag_exists_in_web_element(inner_unit, 'img'):
                    img = self.browser.find_element_by_tag_name('img')
                    if img.get_attribute('class') == 'item_icon':
                        if 'folder_on' in img.get_attribute('src'):
                            folder_dict[local_dir.check_folder_name(inner_unit.text)] = self.gen_folder(inner_unit)
        self.browser.execute_script("window.history.go(-1)")


                        # elif 'file_on' in img.get_attribute('src')):

                        # elif 'document_on' in img.get_attribute('src')):
                        # else:
                        # download text

            #     document_on: download text, include links
            #     file_on
            # no img: download text

        return folder_dict
Esempio n. 2
0
    def access_courses(self):

        course_material_dict = {}
        course_material_dict[self.username] = {}

        for ind, course in enumerate(self.courses): 
            course_material_dict[self.username][local_dir.check_folder_name(course[20:])] = self.build_course_dict(course, ind) 

        return course_material_dict
Esempio n. 3
0
    def build_course_dict(self, first_key, prof_ind):
        course = [first_key]
        
        professor = self.browser.find_elements_by_class_name('courseInformation')[prof_ind].text
        course.append(professor.replace('Instructor: ', '').replace(';', ''))

        self.browser.find_element_by_link_text(first_key).click()
        
        material_dict = {}

        for item_index in range(len(self.browser.find_element_by_id('courseMenuPalette_contents').find_elements_by_tag_name('li'))):
            item = self.browser.find_element_by_id('courseMenuPalette_contents').find_elements_by_tag_name('li')[item_index]

            if item.text == 'Announcements':
                material_dict[item.text] = {}
                item.find_element_by_tag_name('a').click()              
                if self.check_id_exists('content_listContainer'): 

                    content_list_container = self.browser.find_element_by_id('content_listContainer')
                    announcement_text = ''

                    for file_or_folder in content_list_container.find_elements_by_tag_name('li'):
                        announcement_text += file_or_folder.text + '\n' 

                else:
                    content = self.browser.find_element_by_id('content')
                    print(content.find_element_by_id('announcementList').text)

            elif item.text == 'Send Email':
                item.find_element_by_tag_name('a').click()
                
                self.browser.find_element_by_link_text('All Teaching Assistant Users').click()
                list_of_tas = []
                if not self.check_id_exists('inlineReceipt_bad'):
                    list_of_tas = self.browser.find_element_by_id('stepcontent1').find_elements_by_tag_name('li')[0].text[3:].split('; ')
                    course.append(list_of_tas)
                self.browser.execute_script("window.history.go(-1)")
                
                if self.check_link_text_exists('Select Users'):
                    self.browser.find_element_by_link_text('Select Users').click()
                    list_of_students_web_elements = self.browser.find_element_by_id('stepcontent1').find_element_by_name('USERS_AVAIL').find_elements_by_tag_name('option')
                    list_of_students = []
                    for student_web_element in list_of_students_web_elements:
                        if student_web_element.text not in professor and student_web_element.text not in list_of_tas and 'PreviewUser' not in student_web_element.text:
                            list_of_students.append(student_web_element.text)
                    course.append(list_of_students)
                    self.browser.execute_script("window.history.go(-1)")


            elif item.text not in ['Home', 'Announcements', 'Send Email', \
                'My Grades', 'Discussion Board', 'Discussions', \
                'Library Course Reserves', 'Tools', 'Groups']:

                component = local_dir.check_folder_name(item.text)
                material_dict[component] = {}
                item.find_element_by_tag_name('a').click()

                if self.check_xpath_exists('//*div[@class = "noItems container-empty"]'):
                    continue

                elif self.check_id_exists('content_listContainer'):
                    num_of_items = len(self.browser.find_element_by_id('content_listContainer').find_elements_by_tag_name('li'))
                    for unit_index in range(num_of_items):
                        unit = self.browser.find_element_by_id('content_listContainer').find_elements_by_tag_name('li')[unit_index]
                        if self.check_tag_exists_in_web_element(unit, 'img'):
                            img = unit.find_element_by_tag_name('img')
                            if img.get_attribute('class') == 'item_icon':
                                if 'folder_on' in img.get_attribute('src'):
                                    folder_name = local_dir.check_folder_name(unit.find_element_by_tag_name('a').text)
                                    material_dict[component][folder_name] = self.gen_folder(unit)

        self.course_list.append(course)
        self.browser.find_element_by_id('My Chalk').find_element_by_tag_name('a').click()


        return material_dict