def getStudentGrade(self): urlsuffix = getSelectUrl(self.Loginresponse, u'成绩查询') url = self.baseUrl + '/' + urlsuffix self.session.headers['Referer'] = self.baseUrl + "/xs_main.aspx?xh=" + self.student.studentnumber response = self.session.get(url) __VIEWSTATE = get__VIEWSTATE(response) self.session.headers['Referer'] = url data = { "__EVENTTARGET":"", "__EVENTARGUMENT":"", "__VIEWSTATE":__VIEWSTATE, "__VIEWSTATEGENERATOR" : "9727EB43", 'hidLanguage':"", "ddlXN":"", "ddlXQ":"", "ddl_kcxz":"", "btn_zcj" : u"历年成绩".encode('gb2312', 'replace') } response = self.session.post(url,data=data) grades = getGrade(response) for onegrade in grades: year = onegrade["year"] term = onegrade["term"] classNo = onegrade["classNo"] try: yearGrade = YearGrade.get(YearGrade.year == year , YearGrade.student == self.student) except: yearGrade = YearGrade(year=year,student=self.student) yearGrade.save() try: termGrade = TermGrade.get(TermGrade.year == yearGrade , TermGrade.term == int(term)) except: termGrade = TermGrade(year = yearGrade ,term = int(term)) termGrade.save() try: lesson = Class.get(Class.classNo == classNo) except: schedule = ClassSchedule.get(ClassSchedule.year == year, ClassSchedule.term == term) lesson = Class(schedule=schedule, classNo=classNo, name=onegrade["name"] ,type=onegrade["type"], point=float(onegrade["credit"])) lesson.save() try: gradePoint = float(onegrade["gradePonit"]) except: gradePoint = None try: grade = float(onegrade["grade"]) except: grade = None oneLessonGrade = OneLessonGrade(lesson=lesson, term=termGrade, gradePoint=gradePoint, grade=grade) oneLessonGrade.save() return 'ok'
def getClassSchedule(self): self.session.headers['Referer'] = self.baseUrl+"/xs_main.aspx?xh="+self.student.studentnumber urlsuffix = getSelectUrl(self.Loginresponse, u'学生选课情况查询') url = self.baseUrl + '/' + urlsuffix response = self.session.get(url) parsedict = getClassScheduleFromHtml(response) __VIEWSTATE = parsedict["__VIEWSTATE"] __EVENTTARGET = "ddlXQ" year = int(self.student.gradeClass) term = 1 today = datetime.date.today() while today.year>year or (today.year==year and today.month>=7 and term==1): data = { "__EVENTTARGET": __EVENTTARGET, "__EVENTARGUMENT": "", "__VIEWSTATEGENERATOR" : "FDD5582C", "__VIEWSTATE": __VIEWSTATE, "ddLXN": str(year)+"-"+str(year+1), "ddLXQ": str(term), } self.session.headers['Referer'] = url response = self.session.post(url,data) print "正在获取"+str(year)+"-"+str(year+1)+"学年第"+str(term)+"学期课表" parsedict = getClassScheduleFromHtml(response) if parsedict != None: classes = parsedict["classes"] else: continue __VIEWSTATE = getClassScheduleFromHtml(response)["__VIEWSTATE"] classSchedule = ClassSchedule(student=self.student,year=str(year)+"-"+str(year+1),term=term) classSchedule.save() for each in classes: #debug #try: oneClass = Class(schedule=classSchedule , selectClassCode=each["selectClassCode"], classNo=each["classNo"],name=each["name"], type=each["type"], Compulsory= each["Compulsory"],teacher=each["teacher"], point=each["point"], totalTimeInWeek=each["totalTimeInWeek"], timeInTheWeek = each["timeInTheWeek"], timeInTheDay = each["timeInTheDay"], timeInTheTerm=each["timeInTheTerm"], location=each["location"]) oneClass.save() #except KeyError as e: #print each #raise KeyError term = term + 1 if term>2: term = 1 year = year+1 __EVENTTARGET = "ddlXQ" else: __EVENTTARGET = "ddlXN" return 'ok'
def getClassSchedule(): session.headers['Referer'] = baseUrl + "/xs_main.aspx?xh=" + student.stuNumber url = baseUrl + "/tjkbcx.aspx?xh=" + student.stuNumber + "&xm=" + student.urlName + "&gnmkdm=N121605" response = session.get(url, allow_redirects=False) viewState = getClassScheduleFromHtml(response)["__VIEWSTATE"] content=getClassScheduleFromHtml(response)["content"] data = { "__VIEWSTATE": viewState, } classes = getClassFileName(student.stuNumber) # 课程表文件名 oneClass = Class(filename=classes,content=content) oneClass.save() print "成功获取课表"
def getClassSchedule(self): self.session.headers[ 'Referer'] = self.baseUrl + "/xs_main.aspx?xh=" + self.student.studentnumber url = self.baseUrl + "/xskbcx.aspx?xh=" + self.student.studentnumber + "&xm=" + self.student.urlName + "&gnmkdm=N121603" response = self.session.get(url, allow_redirects=False) __VIEWSTATE = getClassScheduleFromHtml(response)["__VIEWSTATE"] year = int(self.student.gradeClass) term = 1 today = datetime.date.today() while today.year > year or (today.year == year and today.month >= 7 and term == 1): data = { "__EVENTTARGET": "xqd", "__EVENTARGUMENT": "", "__VIEWSTATE": __VIEWSTATE, "xnd": str(year) + "-" + str(year + 1), "xqd": str(term), } self.session.headers['Referer'] = url response = self.session.post(url, data) print("正在获取" + str(year) + "-" + str(year + 1) + "学年第" + str(term) + "学期课表") classes = getClassScheduleFromHtml(response)["classes"] __VIEWSTATE = getClassScheduleFromHtml(response)["__VIEWSTATE"] classSchedule = ClassSchedule(student=self.student, year=str(year) + "-" + str(year + 1), term=term) classSchedule.save() for each in classes: oneClass = Class(schedule=classSchedule, name=each["name"], type=each["type"], timeInTheWeek=each["timeInTheWeek"], timeInTheDay=each["timeInTheDay"], timeInTheTerm=each["timeInTheTerm"], teacher=each["teacher"], location=each["location"]) oneClass.save() term = term + 1 if term > 2: term = 1 year = year + 1 print("成功获取课表")