def main(): st_dict = get_st_dict("tmp") tmp = get_name_pwd_from_console() crawler = PAT_crawler(tmp[0],tmp[1]) while crawler.logined() == False: print "login error! try your account and password again!\n" tmp = get_name_pwd_from_console() crawler.login(tmp[0],tmp[1]) st_dict = crawler.get_submissions(st_dict) # print st_dict #return keywords_set = [ ['cin','cout'],['class'],['operator','class'],['class','virtual'] ] #problems = [str(x+1001) for x in range(PROBLEM_NUM)] problems = [ string.ascii_uppercase[x] for x in range(PROBLEM_NUM)] tmp = {} for i in range(len(problems)): tmp[problems[i]] = keywords_set[i] keywords_set = tmp #print keywords_set for key in st_dict: for problem_id in problems: if problem_id in st_dict[key].submissions: st_dict[key].score = st_dict[key].score + st_dict[key].submissions[problem_id].score if crawler.code_filter(st_dict[key].submissions[problem_id].code_url,keywords_set[problem_id]) == True: st_dict[key].submissions[problem_id].pass_filter = True #print st_dict write_txt(st_dict) write_xls(st_dict) save_codes(crawler,st_dict)
def main(): EncodeType = sys.getfilesystemencoding() args = args_process() st_list = student_model.get_st_list(args.student_list_file) tmp = get_name_pwd_from_console() crawler = PAT_crawler(tmp[0],tmp[1]) while crawler.logined() == False: print "login error! try your account and password again!\n" tmp = get_name_pwd_from_console() crawler.login(tmp[0],tmp[1]) try: fp = open("result.txt","a+") except IOError: print "Error open result.txts error!" raw_input("Press Enter to continue......") sys.exit() print "===start testing,see the result in console or result.txt ======================\n" ip2ids = {} while True: try: for i in range(len(st_list)): current_ip = crawler.get_ip_by_name(st_list[i].id) if current_ip == "": #never logined continue #login if ip2ids.has_key(current_ip) == False: ip2ids[current_ip] = [] if ip2ids[current_ip].count(st_list[i])==0: ip2ids[current_ip].append(st_list[i]) if current_ip!="127.0.0.1" and len(ip2ids[current_ip]) > 1: content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())) content = content + "ip:%s\n" % current_ip content = content + "logined students:\n"+'\n'.join(str(tst) for tst in ip2ids[current_ip]) print content.decode('utf-8').encode(EncodeType) fp.write(content) fp.flush() llen = len(st_list[i].ips) if llen == 0: st_list[i].ips.append(current_ip) else: if st_list[i].last_ip != current_ip: #different login ip detected #print last ip and current ip #print current ip has logined whos #print this id has logined which ips if st_list[i].ips.count(current_ip)==0: st_list[i].ips.append( current_ip) content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime('%Y-%m-%d %H:%M',time.localtime(time.time())) content = content + str(st_list[i])+":\n" content = content + "logined ip:\n"+'\n'.join(st_list[i].ips) content = content + '\ncurrent_ip:'+current_ip print content.decode('utf-8').encode(EncodeType) fp.write(content) fp.flush() st_list[i].last_ip = current_ip except KeyboardInterrupt: print "exting..." fp.close() print "bye" raw_input("Press Enter to continue......") sys.exit()
def main(): EncodeType = sys.getfilesystemencoding() args = args_process() st_list = student_model.get_st_list(args.student_list_file) tmp = get_name_pwd_from_console() crawler = PAT_crawler(tmp[0], tmp[1]) while crawler.logined() == False: print "login error! try your account and password again!\n" tmp = get_name_pwd_from_console() crawler.login(tmp[0], tmp[1]) try: fp = open("result.txt", "a+") except IOError: print "Error open result.txts error!" raw_input("Press Enter to continue......") sys.exit() print "===start testing,see the result in console or result.txt ======================\n" ip2ids = {} while True: try: for i in range(len(st_list)): current_ip = crawler.get_ip_by_name(st_list[i].id) if current_ip == "": #never logined continue #login if ip2ids.has_key(current_ip) == False: ip2ids[current_ip] = [] if ip2ids[current_ip].count(st_list[i]) == 0: ip2ids[current_ip].append(st_list[i]) if current_ip != "127.0.0.1" and len( ip2ids[current_ip]) > 1: content = "\n%s:---------one ip with multiple id ---------\n" % time.strftime( '%Y-%m-%d %H:%M', time.localtime(time.time())) content = content + "ip:%s\n" % current_ip content = content + "logined students:\n" + '\n'.join( str(tst) for tst in ip2ids[current_ip]) print content.decode('utf-8').encode(EncodeType) fp.write(content) fp.flush() llen = len(st_list[i].ips) if llen == 0: st_list[i].ips.append(current_ip) else: if st_list[i].last_ip != current_ip: #different login ip detected #print last ip and current ip #print current ip has logined whos #print this id has logined which ips if st_list[i].ips.count(current_ip) == 0: st_list[i].ips.append(current_ip) content = "\n%s:---------one id with multiple ip ---------\n" % time.strftime( '%Y-%m-%d %H:%M', time.localtime(time.time())) content = content + str(st_list[i]) + ":\n" content = content + "logined ip:\n" + '\n'.join( st_list[i].ips) content = content + '\ncurrent_ip:' + current_ip print content.decode('utf-8').encode(EncodeType) fp.write(content) fp.flush() st_list[i].last_ip = current_ip except KeyboardInterrupt: print "exting..." fp.close() print "bye" raw_input("Press Enter to continue......") sys.exit()