CET 四六级查分器
来源:互联网 发布:java开源系统源码 编辑:程序博客网 时间:2024/05/06 02:57
六级考完后,忍不住内心的兴奋之情,于当日完开始编写CET查分器,并于昨晚完成了提交表单方面的问题,由于自己一直很懒,header头部没加,所以,不给我返回信息。。。
然后就去请教了某位大神,最后请教过程中看了大神的blog,发现原来是自己没加header头部的原因,于是乎,赶紧改~
然后今天又是半个下午加半个晚上,终于搞定了,弄了一个还算简单的图形界面,由于信息有限,不能像某位大神一样,可以只要输入学校名就能查的功能,不过这样也有好处,那就是防止信息泄露,哎~话说我当时就干过这么缺德的事情(http://wenku.baidu.com/view/633fc946a8956bec0975e3ce.html 查各个学校的前六位准考证号的,但是,其实最好不要。。。除非你是真的忘了自己的准考证号)
搞得有点累,也有点兴奋,其实昨晚就已经实现了终端下的功能,今天下午和晚上主要是在搞图形界面呢!
代码还是有多地方需要改进的,这博文我已经修改好几次了,代码也替换了好几次- - 囧rz。(输入准考证前六位部分已经修改成可以输入多个准考证号,只要每个准考证号之间加入一个',' 英文输入的逗号即可)
——关于效率
比较纠结的地方就是如何创建进程,这个有点烦,我测试了很多次,效率如下:
2G ,双核CPU(抱怨:CPU有点差劲,当初机房分电脑的时候,学长们就有意见,后来对面数模晚一年分电脑,居然分到了i5的处理器!!!次奥,搞数模有个office2010么就够了咯。。。真是的)
运行期间,CPU大概会占40%左右
经过测试,60个线程是比较优的,超过100个线程就没有实质性地上升空间了,可能是线程中加减锁的问题吧
运行一个地区号(有些学校可能会有多个地区号,比如说浙工商,ZJU,ZJUT,像ZJU有4个地区号330011,330012,330013,330015,那么如果你不确定自己是哪个,那么就需要4倍的时间了)所需的时间在4分钟左右,不同的计算机可能有点不同。
不管怎样,先上源代码吧,哈哈~
主函数部分:看到那个冗长的header头部没,全是我一字一字地加上去的T T
Main.py__author__ = 'glcsnz123'#_*_encoding:utf-8_*_import urllib2, urllibimport sys, timeimport thread, threadingfrom GUI import GUIFramefrom RunMulThread import RunMulThreads, RunMulimport wxcefy = []def Check(stid="**", name=u"**"): #print name,type(name)330020121101729 #name = unicode(name, "utf-8") post_data = urllib.urlencode({"id": stid.decode("gbk"), "name": name.encode("gbk")}); #print post_data headers = {"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",\ "Accept-Charset": "GBK,utf-8;q=0.7,*;q=0.3", "Accept-Encoding": "gzip,deflate,sdch",\ "Accept-Language": "zh-CN,zh;q=0.8", "Cache-Control": "max-age=0", "Connection": "keep-alive",\ "Content-Length": "36", "Content-Type": "application/x-www-form-urlencoded",\ "Cookie": "cnzz_a30023677=4; sin30023677=; rtime30023677=5; ltime30023677=1356177904700; cnzz_eid30023677=19927958-1318821986-http%3A//www.baidu.com/s%3Fwd%3D99%25CB%25DE%25C9%25E1%26rsv_bp%3D0%26rsv_spt%3D3%26oq%3D9; searchtime=1356177913" , "Host": "cet.99sushe.com", "Origin": "http://cet.99sushe.com", "Referer": "http://cet.99sushe.com/",\ "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.20 (KHTML, like Gecko) Chrome/25.0.1337.0 Safari/537.20" }; pst = urllib2.Request("http://cet.99sushe.com/s", headers=headers); try: pst = urllib2.urlopen(pst, post_data) except Exception, e: print pst, post_data; html = pst.read() return html.decode("gbk")def GetName(): #name = raw_input(u"请输入你的姓名:"); return GUIFrame.cetnamedef GetLevel(): #return raw_input("CET?"); return GUIFrame.cetlevanslist = [];mylock = thread.allocate_lock()hole = range(1, 100000)def LoopOne(stid, name): while True: try: mylock.acquire() if len(hole) <= 0: break i = hole[0] del hole[0] finally: mylock.release() result = Check(stid + str("%05d" % i), name) if len(result) > 20: print result anslist.append(result.split(',')) cefy.append(stid + str("%05d" % i))def GetLocalNum(): #return "330020" #return raw_input("请输入准考证号的前六位:") return GUIFrame.localid.split(",")def GetYear(date): year = int(str(date[0])[2:]) if date[1] < 8: year -= 1 return str(year)def Init(): app = wx.PySimpleApp(); frame = GUIFrame() frame.Show(True) app.MainLoop();def RunMul(): apps = wx.PySimpleApp(); runmt = RunMulThreads() runmt.Show(True) runmt.start() apps.MainLoop();if __name__ == "__main__": Init() name = GetName(); try: names = name[0:6] except Exception, e: exit() date = time.localtime(time.time()) stidls = GetLocalNum() RunMulThreads.cetProc = 0 thread.start_new_thread(RunMul, ()) time.sleep(1) ape = -1 for stid in stidls: ape += 1 if len(stid) != 6: RunMulThreads.ShowLabel = u" 正在努力创建60个线程...\n\n创建完成!^0^~ 开始查找..." RunMulThreads.cetProc = 100 RunMulThreads.anslist.append(u"输入有误,程序终止~\n错误准考证号:" + str(stid)) break hole = range(1, 100000) stid += GetYear(date) if int(date[1]) >= 8 or int(date[1]) < 2: stid += '1' else: stid += '2' cetlv = GetLevel() if cetlv == '4': stid += '1' else: stid += '2' print stid #RunMulThreads.ShowLabel = "" time.sleep(1); for i in range(0, 60): thread.start_new_thread(LoopOne, (stid, names)) time.sleep(0.5); #pass RunMulThreads.ShowLabel = u" 正在努力创建60个线程...\n\n创建完成!^0^~ 开始查找..." now = len(hole) * 1.0; while True: print "当前完成度:%.2f%%" % (100.0 - (len(hole) * 100.0 / now)) RunMulThreads.cetProc = (100.0 - (len(hole) * 100.0 / now)) / (len(stidls)) + ape * (100.0 / len(stidls)) if len(hole) == 0: if RunMulThreads.cetProc > 90: RunMulThreads.cetProc = 100 break time.sleep(15); #result=Check() #print result #anslist.append(result.split(',')) for i in range(len(anslist)): tmp = anslist[i] scors = u"姓名: " + tmp[-1] scors += u"\n准考证号: " + cefy[i] scors += u"\n学校: " + tmp[-2] scors += u"\n总分: " + tmp[-3] scors += u"\n听力: " + tmp[1] scors += u"\n阅读: " + tmp[2] scors += u"\n综合: " + tmp[3] scors += u"\n写作: " + tmp[4] RunMulThreads.anslist.append(scors) time.sleep(100000)
然后是信息填写部分的GUI代码,原本是打算信息填写部分的代码了
原本是想将所有的GUI内容都写入一个文件中的,但是,到最后发现这样有点乱,所以,本着简单的原则,就放到了两个文件中去,接下来是实现代码查看功能的GUI代码:
GUI.py
__author__ = 'glcsnz123'#_*_encoding:utf-8_*_import wximport sysglobal sch, iddict, schdictsch = [u'浙江师范大学', u'浙江工商大学', u'浙江大学', u'宁波大学', u'绍兴文理学院', u'湖州师范学院', u'浙江工业大学', u'其他']iddict = ["330020", "330382,330381", '330011,330012,330013,330015', '330030', '330090,330091,330092', '330100',\ '330361,330362', '330020'];schdict = {}for i in range(len(sch)): schdict.setdefault(sch[i], iddict[i])class GUIFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, parent=None, id=-1, title="CET4|6 ShowScore", size=(380, 300)) self.panel = wx.Panel(self, id=-1); self.panel.SetBackgroundColour("white") #create the radiobox self.cetrb = wx.RadioBox(self.panel, id=-1, label="CET Level", name="radiobox", choices=['CET4', 'CET6'], pos=(120, 30)) #create the school list self.cetcs = wx.Choice(self.panel, id=-1, choices=sch, name="choice", pos=(50, 120)) self.cetcs.SetStringSelection(sch[0]) #create the textctrl self.cettc = wx.TextCtrl(self.panel, -1, u"准考证前六位,多个输入请用','隔开", pos=(170, 120), size=(150, 30)) self.cettc.Show(False); self.cetname = wx.TextCtrl(self.panel, -1, u"请输入您的姓名", pos=(100, 170), size=(150, 30)) #create the static text self.cetsc = wx.StaticText(self.panel, -1, u"you can't see this!", pos=(180, 123), size=(150, 30)) self.cetsc.SetLabel(schdict[self.cetcs.GetStringSelection()]) #create the submit button self.cetbut = wx.Button(self.panel, -1, label=u"确定", pos=(135, 210)) #create the bind self.Bind(wx.EVT_CHOICE, self.OnOtherChoice, self.cetcs) self.Bind(wx.EVT_BUTTON, self.OnSubmit, self.cetbut) self.Bind(wx.EVT_CLOSE, self.OnClose) def OnClose(self, event): sys.exit() def OnSubmit(self, event): self.__class__.cetname = self.cetname.GetValue() if self.cetrb.GetSelection() == 0: self.__class__.cetlev = '4' else: self.__class__.cetlev = '6' if self.cetcs.GetStringSelection() == u"其他": self.__class__.localid = self.cettc.GetValue() else: self.__class__.localid = self.cetsc.GetLabel() self.Destroy() def OnOtherChoice(self, event): if self.cetcs.GetStringSelection() == u"其他": self.cetsc.Show(False) self.cettc.Show(True) self.Refresh() elif self.cetcs.GetStringSelection() != "": self.cettc.Show(False) self.cetsc.Show(True) self.cetsc.SetLabel(schdict[self.cetcs.GetStringSelection()]) self.Refresh()if __name__ == '__main__':#main function app = wx.PySimpleApp(); frame = GUIFrame() frame.Show(True) app.MainLoop();
RunMulThread.py
__author__ = 'glcsnz123'#_*_encoding:utf-8_*_import wximport thread, threading;import sys, timer, timeglobal runmtclass RunMulThreads(wx.Frame, threading.Thread): def __init__(self): wx.Frame.__init__(self, parent=None, id=-1, title="CET4|6 ShowScore", size=(400, 400)) threading.Thread.__init__(self) self.panel = wx.Panel(self, id=-1); self.panel.SetBackgroundColour("white") self.curnow = 0 #create the Gauge self.cetGua = wx.Gauge(self.panel, -1, 100, name="gauge", pos=(50, 90), size=(300, 20)) self.__class__.cetProc = 0 self.cetGua.Show(False) #create the staicText self.__class__.ShowLabel = u" 正在努力创建60个线程..." self.cetShowSt = wx.StaticText(self.panel, -1, self.__class__.ShowLabel, pos=(120, 25)) #create the staticText self.cetRes = wx.StaticText(self.panel, -1, u"you can't see me!", pos=(140, 130)) self.cetRes.Show(False) self.__class__.anslist = []; #create the button self.cetprebut = wx.Button(self.panel, -1, label=u"上一个", pos=(100, 300)) self.cetnextbut = wx.Button(self.panel, -1, label=u"下一个", pos=(200, 300)) self.cetprebut.Show(False) self.cetnextbut.Show(False) #create the bind self.Bind(wx.EVT_BUTTON, self.PreResult, self.cetprebut) self.Bind(wx.EVT_BUTTON, self.NextResult, self.cetnextbut) self.Bind(wx.EVT_CLOSE, self.ErrorLog) def ErrorLog(self, event): try: f = open("error.log", "a") f.write("program error exit~\n") for line in self.__class__.anslist: f.write(line) except Exception, e: print "write error" finally: f.close() self.Destroy() def PreResult(self, event): self.curnow -= 1 self.curnow %= len(self.__class__.anslist) self.cetRes.SetLabel(self.__class__.anslist[self.curnow]) def NextResult(self, event): self.curnow += 1 self.curnow %= len(self.__class__.anslist) self.cetRes.SetLabel(self.__class__.anslist[self.curnow]) def run(self): while True: self.cetShowSt.SetLabel(self.__class__.ShowLabel) time.sleep(1); if len(self.cetShowSt.GetLabel()) > 30: break; time.sleep(1) self.cetGua.Show(True) while True: self.cetGua.SetValue(self.__class__.cetProc) time.sleep(6) if self.__class__.cetProc >= 100: self.cetGua.SetValue(self.__class__.cetProc) break; self.cetRes.SetLabel(u"努力处理数据中...") self.cetRes.Show(True) time.sleep(1) self.curnow = 0 if len(self.__class__.anslist[self.curnow]) > 0: self.cetRes.SetLabel(self.__class__.anslist[self.curnow]) self.cetprebut.Show(True) self.cetnextbut.Show(True) else: self.cetRes.SetLabel(u"查找失败~~~~~~")def RunMul(): app = wx.PySimpleApp(); runmt = RunMulThreads() runmt.Show(True) app.MainLoop();if __name__ == '__main__':#main function RunMul(); #print "yes" #thread.start_new_thread(RunMul, ()) #time.sleep(2000)
GUI是用wxPython写的,效果略比Java的Swing好
以上就是源代码部分,还有很多我的注释掉的调试信息
Readme.txt
1、程序还有部分bug没有修复,在靠近下一次考试可以查询的时候,可能就无法查询成功,此时就必须修改自己电脑上的系统时间了,可以将时间调回到上次可以查询成绩的下一个月,然后再进行查询。
2、程序会生成一个quest.log和error.log,这两个文件主要是用来存放错误信息,因为查找过程中有部分信息会查找失败,失败的会放入quest.log,但是很不辛的是,由于多线程机制,导致写入过程都会失败,因此,quest.log只是作为日后改进所放置的,并无实质性的意义。而error.log则是当程序异常退出时,将已经查询到的信息写入这个文本。
3、任何问题,可以联系我 (e-mail:425797155@qq.com)~希望能不断改进修复bug!
4、本程序仅限于WIN7 用户,其他系统的用户可能会无法运行(lz在WIN XP上测试运行时失败)。
接下来就是把它变成.exe文件了,嗯~开始干活!
.exe文件下载地址:http://gripleaf.ys168.com 下download文件夹中cet四六级查分工具.zip
为了能够让大家尽快知道自己的成绩,我在打包成exe过程中选用了控制台模式,大家可以通过控制台来看到查询进度,由于控制台编码为ASCII,而我使用的是UTF-8,所以会出现乱码情况。
- CET 四六级查分器
- 2017年6月英语 CET 四六级考试查询准考证方法
- 基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0
- 四六级
- 四六级
- cet-4
- cet 4
- 关于CET
- CET考试
- CET-4
- CET-6
- CET-4
- CET APP
- 四六级报名
- 谈英语四六级
- 汉语四六级
- 中文四六级
- 四六级,考研,MBA
- hibernate执行sql获取泛型对象
- java正则表达式
- apache shiro database
- 点亮led过程分析
- 设计模式之结构型模式一
- CET 四六级查分器
- 断章——卞之琳
- 银行IT部门科技管理流程管控工作发展之路
- Codeforces Round #134 (Div. 2)——B
- hibernate 乐观锁与悲观锁使用
- css定位详解
- 高仿QQ2012登录界面
- Flex调试工具的安装(Flash 调试 IE Firefox )
- 那些高中时曾经背得烂熟的古文(滕王阁序,阿房宫赋, 兰亭集序 , 师说,蜀道难 ...)再一次读读吧,慢慢的读,突然很想哭...有些岁月果真不曾忘怀