def GetStudentScore(Account,Password,Term): atry=actiontojwc2.Tojwc() # zhanghao="020252009012"; get=atry.trytoconnect(Account,Password,Term) if get==0: try: print time.ctime()+"\t"+"抓取学生成绩---学号:"+Account atry.getContents() parser=atry.GetScore("http://jwc.ouc.edu.cn:8080/ouc/SS018.do") #name=parser.findAll('p')#border 属性唯一 number=parser.findAll('font')#number[3]为个人及格分数 chengji=parser.findAll('table',align="center")#center属性唯一 count=SQLHelper.GetCountOne("Mark", "UserID", Account); if count==0: field=["UserID","PassScore","MarkContent"] #MySQLdb.escape_string()参数必须是string类型的 value=[Account,MySQLdb.escape_string(str(number[3])),MySQLdb.escape_string(str(chengji[0]))] insert=SQLHelper.Insert("Mark", field, value) if insert==1: print time.ctime()+"\t成绩---"+Account+"---Insert OK" else: print "插入个人成绩出现程序上的错误,请检查!!" else: fields=["PassScore","MarkContent"] values=[MySQLdb.escape_string(str(number[3])),MySQLdb.escape_string(str(chengji[0]))] update=SQLHelper.Update("Mark", fields, values, "UserID", Account) if update==1: print time.ctime()+"\t成绩---"+Account+"---Update OK" else: print "插入个人成绩出现程序上的错误,请检查!!" atry.logout() print time.ctime()+"\t"+"学生成绩更新完成。" except Exception: atry.logout() print traceback.print_exc() return 3 else : if get==1: print time.ctime()+"\t成绩---"+Account+"登陆失败,请检查用户名、密码是否正确。" if get==2: print time.ctime()+"\t成绩---"+Account+"该用户已经登录,请登出或稍后再试!"
def lineReceived(self,data): information=data.split('|||') #登录 if information[0]=="login": if information[1] not in self.factory.users: #检查是否第一次登录 self.checkFirstLogin(information[1], information[2]) print "number:"+information[1] else: self.sendLine("login|||failure|||2") #不是登录就想获取数据! elif not self.transport.getPeer().host in self.factory.ip: self.sendLine("不登录就想获取数据!") self.transport.loseConnection() #模块定制 if information[0]=="options": # flag==下次是否仍显示模块定制对话框 # jwcnews==是否定制教务处新闻 # xknews==是否定制选课系统新闻 # facultynews==是否定制院系新闻 sql.Update("Options", ["flag"], [information[1]], "UserNumber", self.student[1]) sql.Update("Options", ["jwcnews"], [information[2]], "UserNumber", self.student[1]) sql.Update("Options", ["xknews"], [information[3]], "UserNumber", self.student[1]) sql.Update("Options", ["facultynews"], [information[4]], "UserNumber", self.student[1]) #好友 if information[0]=="friends": #搜索 if information[1]=="search": self.searchFriend(information[2]) #添加 if information[1]=="add": self.addFriend(information[2], information[3],information[4]) #删除 if information[1]=="delete": self.deleteFriend(information[2],information[3]) self.deleteFriend(information[3], information[2]) #发送好友列表 if information[0]=="getfriends": self.sendFriends() #发送消息 if information[0]=="message": self.sendMsg() #发送新闻 #按页数返回10条记录 if information[0]=="get10news": self.send10News(information[1],information[2]) #按id返回最新新闻 if information[0]=="getnewsbyid": self.sendNewsbyID(information[1],information[2]) #按id返回内容 if information[0]=="getnewscontent": print information self.sendNewsContent(information[1],information[2]) #客户端请求新闻页数 if information[0]=="getnewspage": self.sendNewsPage(information[1]) # self.sendNewsPage("15") self.send10News("0", information[1]) # self.send10News("0", "15") # self.th.callInThread(self.listennews) # self.th.callInThread(self.listenMsg) #发送课程信息 if information[0]=="getcourses": # print information self.sendCourse(information[1]) #发送学期列表 if information[0]=="getterm": if self.firstlogin==False: self.sendTerm() #发送好友学期列表 if information[0]=="getfriendterm": self.sendFriendTerm(information[1]) #发送好友课程 if information[0]=="getfriendcourses": self.sendFriendCourse(information[1],information[2]) #客户端通知服务器开始检测是否有最新新闻和最新消息,一旦触发,服务器每2s验证一次 if information[0]=="startlistening": threads.deferToThread(self.listennews) threads.deferToThread(self.listenMsg) #注销 if information[0]=="logout": self.transport.loseConnection()