Ejemplo n.º 1
0
 def select_lesson(self, lesson_list):
     data = copy.deepcopy(self.base_data)
     data['Button1'] = '  提交  '.encode('utf-8')
     print("\n正在抢课:")
     for lesson in lesson_list:
         data[lesson.code] = 'on'
         print(lesson.name)
     response = self.login.s.post(self.login.headers['Referer'], data=data, headers=self.login.headers)
     selector = etree.HTML(response.text)
     Lesson.show_error(selector)
     print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
     self.set_view_state(selector)
     self.count_lesson = already(selector)
     return len(lesson_list)
Ejemplo n.º 2
0
 def select_lesson(self, lesson):
     data = {
         '__EVENTTARGET': 'Button1',
         '__VIEWSTATE': self.__VIEWSTATE,
         'xkkh': lesson.number,
         'RadioButtonList1': '1'
     }
     response = self.login.s.post(self.login.headers['Referer'],
                                  data=data,
                                  headers=self.login.headers)
     if response.status_code != 200:
         print("抢课失败,错误代码:" + response.status_code)
     selector = etree.HTML(response.text)
     print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
     Lesson.show_error(selector)
     self.set_view_state(selector, 'xsxjs_form')
Ejemplo n.º 3
0
    def loadScript(self,lessonScriptPath):
        lessonScriptPath = self.completeLessonScriptPath(lessonScriptPath)

        courseName = 'STANDARD_COURSE' ###- TODO, implement get course name
        course = Course.Course(courseName,self.application)

        moduleName = self.getModuleNameFromLessonScriptPath(lessonScriptPath)
        lessons = {}
        module = Module.Module(moduleName,lessons,course)

        lessonName = self.getLessonNameFromLessonScriptPath(lessonScriptPath)
        pages = {}
        module.lessons[lessonName] = Lesson.Lesson(lessonName,pages,module)

        try :
            with open(lessonScriptPath,"r",encoding="utf-8") as scriptFile :
                for lessonScriptLine in scriptFile :
                    if lessonScriptLine != '\n' :
                        pageName = self.getPageNameFromLessonScriptLine(lessonScriptLine)
                        pageScript = lessonScriptLine.strip()
                        module.lessons[lessonName].pages[pageName] = Page.Page(pageName,pageScript,module.lessons[lessonName])
        except :
            with open(lessonScriptPath,"+w",encoding="utf-8") as scriptFile : pass

        return module.lessons[lessonName]
Ejemplo n.º 4
0
def lessonList(t):
    try:
        lessonList = Io.LessonIo().read_lesson()
    except:
        lessonList = []
    print("您所教的科目是:%s" % t.teacher_major)
    lessonMajor = t.teacher_major
    lessonTeacher = t.teacher_name
    # 从键盘输入所交课程最多人数
    lessonNum = input("请输入您所教课程最多人数:")
    # 从键盘读取您要授课的时间
    lessonTime = input("请输入您要授课的时间:")
    # 创建一个课程实例
    l = Lesson.Lesson(lessonMajor, lessonTeacher, lessonNum, lessonTime)
    print("您添加的课程为:%s--人数为:%s--时间为:%s" %
          (l.lesson_name, l.lesson_num, l.lesson_time))
    # 将添加的信息写入日志中
    log = "%s老师添加课程:%s--人数为:%s--时间为:%s" % (t.teacher_name, l.lesson_name,
                                           l.lesson_num, l.lesson_time) + "\n"
    # 将日志写入
    Io.Log().wirite_log(log)
    # 将课程实例写入课程列表中
    lessonList.append(l)
    # 将课程写入文件中
    b = Io.LessonIo().wirite_lesson(lessonList)
    if b == True:
        print("添加课程表成功!")
    else:
        print("添加课程失败!")
Ejemplo n.º 5
0
def get_all_information_of_lesson(selector, lesson):
    lesson_list = []
    lessons_tag_list = selector.xpath(
        '//table[@id="xjs_table"]/tr[1]/following-sibling::tr')
    for lesson_tag in lessons_tag_list:
        # num = lesson_tag.xpath('td[1]/text()')[0]
        teacher = lesson_tag.xpath('td[2]/a/text()')[0]
        lesson_time = lesson_tag.xpath('td[6]/text()')[0]
        surplus = int(lesson_tag.xpath('td[12]/text()')[0]) - int(
            lesson_tag.xpath('td[15]/text()')[0])
        code = lesson_tag.xpath('td[16]/input/@value')[0]
        lesson = Lesson.Lesson(code, lesson.name, lesson.code, teacher,
                               lesson_time, str(surplus))
        lesson_list.append(lesson)
    return lesson_list
Ejemplo n.º 6
0
def get_lessons(selector):
    lesson_list = []
    lessons_tag_list = selector.xpath('//table[@id="kcmcGrid"]/tr[1]/following-sibling::tr')
    for lessons_tag in lessons_tag_list:
        code = lessons_tag.xpath('td[1]/input/@name')[0]
        # num = lessons_tag.xpath('td[2]/a/@onclick')[0][52:81]
        class_name = lessons_tag.xpath('td[3]/a/text()')[0]
        num = lessons_tag.xpath('td[4]/text()')[0]
        teacher_name = lessons_tag.xpath('td[5]/a/text()')[0]
        lesson_time = lessons_tag.xpath('td[6]/@title')
        if lesson_time:
            lesson_time = lesson_time[0]
        else:
            lesson_time = "空"
        surplus = lessons_tag.xpath('td[11]/text()')[0]
        lesson = Lesson.Lesson(num, class_name, code, teacher_name, lesson_time, surplus)
        lesson_list.append(lesson)
    return lesson_list
Ejemplo n.º 7
0
def get_all_lesson(selector):
    lesson_list = []
    lessons_tag_list = selector.xpath(
        '//table[@id="kcmcgrid"]/tr[1]/following-sibling::tr')
    for lesson_tag in lessons_tag_list:
        num = lesson_tag.xpath('td[1]/a/text()')
        # 检验是否为无效的tr标签
        if num:
            num = num[0]
        else:
            break
        code = lesson_tag.xpath('td[1]/a/@onclick')[0]
        pattern = "xkkh(.+?)xh"
        code = re.search(pattern, code).group()[5:-3]
        lesson_name = lesson_tag.xpath('td[2]/a/text()')[0]
        surplus = lesson_tag.xpath('td[10]/text()')[0]
        lesson = Lesson.Lesson(num, lesson_name, code, "待选择", "待选择", surplus)
        lesson_list.append(lesson)
    return lesson_list