def _crawl_task(self, contest_id, row, db_session): cells = row.cssselect('td') symbol = cells[0].text_content() title = cells[1].text_content() link_url = cells[1].find('a').get('href') link_match = re.match(r'/tasks/(.+)$', link_url) if link_match: path = link_match.group(1) else: raise RuntimeError('no task link') submit_url = cells[4].find('a').get('href') submit_match = re.match(r'/submit\?task_id=(\d+)$', submit_url) if submit_match: problem_id = int(submit_match.group(1)) else: raise RuntimeError('no submit link') problem = Problem(problem_id=problem_id, title=title) task = Task(contest_id=contest_id, problem_id=problem_id, symbol=symbol, path=path) logger.info(problem) logger.info(task) db_session.add(problem) db_session.add(task)
def _formulate_problem(a, b, p, q): # Find midpoint deltas = b.coords - a.coords c = a.coords + deltas / 2.0 # Get perpendicular slope v = array([deltas[1], -deltas[0]]) v /= norm(v) s = Slope(v) return Problem(c, s, a, b, p, q)