def getProblemList(self, cid): ctype = globalVar.BASE_CONF.get('contest', 'ctype') cpass = globalVar.BASE_CONF.get('contest', 'cpass') data = {'id': cid, 'type': ctype} pwdProbleUrl = globalVar.OJ_CONF.get('urls', 'pwdProblems') resp = RequestUtil.doGet(pwdProbleUrl, data) \ if cpass == '1' else RequestUtil.doGet(AojApi.getUrl('problems'), data) # 解析网页数据 soup = BeautifulSoup(resp.text, "lxml") # 仅获取题目和id pList = [] allProblemDiv = soup.find_all('div', id=re.compile(r'title_\d*')) if not allProblemDiv: PrintUtil.warn("题目空了,你可能已经AK了.") sys.exit(0) for pdiv in allProblemDiv: p = Problem() p.pid = re.sub("\D", "", pdiv['id']) title = pdiv.find('div', class_='nav').string.split('.')[1].strip() tempStrs = title.split('(') p.score = '分数:' + re.sub("\D", "", tempStrs[len(tempStrs) - 1]).strip() p.title = title.split('(')[0].strip() pList.append(p) # 按分数排序 pList = sorted(pList, key=lambda pList: pList.score) return pList
def saveProblemList(self): PrintUtil.info('正在缓存题目信息...') pList = self.getProblemList(globalVar.BASE_CONF.get('contest', 'cid')) if not pList: PrintUtil.warn('获取题目信息失败') try: with open(globalVar.BASE_PATH + 'problemList', 'wb') as file_object: pickle.dump(pList, file_object) except Exception as e: PrintUtil.error('缓存失败 :(') print(e) pass