def get_return(self, num): sql = sqll.SQL() self.get_code() self.log_in(num) if self.post_code(): sql.un_public(self.oj, self.proid, self.local_runid) return end_url = self.get_end_url() runid = self.get_runid() for i in range(10): #设定得到结果10次,每次延时1秒,如何得不到结果就设定为提交失败 self.url_open(end_url) result = self.get_result(runid) if result[0] == '判题中...': time.sleep(1) continue else: if result[0] == 'CompileError': self.get_ce_msg(runid) self.write_sql(result) return result = ['判题失败', '0', '0'] self.write_sql(reqult) print('提交失败')
def get_ce_msg(self, runid): ce_url = 'http://acm.hdu.edu.cn/viewerror.php?rid=%d' % runid self.url_open(ce_url) p = re.compile(r'<pre>[\d\D]*?</pre>') p = p.search(self.page) sql = sqll.SQL() sql.insert_ce(p.group(0), self.local_runid)
def get_code(self): sql = sqll.SQL() data = sql.select_code(self.local_runid) self.data = { 'problemid': data[0], 'language': data[1], 'usercode': data[2] } self.proid = int(data[0])
def get_pip(dis): #这个是过去管道的数据的。dis是ioj-消息队列的映射 sql = sqll.SQL() while True: file_name = '../fifo/runing' f = open(file_name, 'r') runid_list = f.readlines() f.close() for runid in runid_list: runid = int(runid) oj = sql.select_oj(runid) #根据运行好得到这个oj是哪个 print(runid) dis[oj].put(runid)
def get_proxies(cls): #加载代理模块 try: s = GetReq.proxies[0] #如果这个变量不存在可能会抛出异常 except: #还不太理解静态方法和类方法,先写个破玩意用这,留着以后理解了再改 print('加载代理') GetReq.proxies = [{}] sql = sqll.SQL() ip_list = sql.find_ip() for i in ip_list: if i[0] == '#': continue else: GetReq.proxies.append({'http': i})
def run(jb, req_out): sql = sqll.SQL(); while True: proid = jb.get(); if proid == 'end': jb.put('end'); #接收到end信号将信号重新发回队列 return; proid = int(proid); req = copy.deepcopy(req_out); req.get_request(proid); if req.end == True: print('end~~~'); jb.put('end'); #向消息队列发送一个end信号 return ; sql.insert(req);
def th_check(ip_list): th_list = [] jbin = queue.Queue() jbout = queue.Queue() jbdel = queue.Queue() for i in range(100): t = th.Thread(target=check, args=(jbin, jbout, jbdel)) t.setDaemon(True) t.start() th_list.append(t) for i in ip_list: jbin.put(i) jbin.put('end') for i in th_list: i.join() sql = sqll.SQL() # while not jbout.empty(): # sql.insert_ip(jbout.get()); while not jbdel.empty(): sql.del_ip(jbdel.get()) print('del :')
print(runid); f = open('../fifo/runing' , 'w'); print(runid); f.write(runid); f.close() if __name__ == '__main__': sql = sqll.SQL(); a = sql.select_no_return(); print(a) poll = mu.Pool(10); for i in a: runid = '%d\n' % i; poll.apply_async(run , args = (runid ,)); poll.close(); poll.join(); """ if __name__ == "__main__": sql = sqll.SQL() a = sql.select_no_return() for i in a: runid = '%d\n' % i f = open('../fifo/runing', 'w') print(runid) f.write(runid) f.close()
def write_sql(self, s): sql = sqll.SQL() sql.write_result(s, self.local_runid)