Пример #1
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteSpoj.pattern_contest.search(url_path)
            problem.id = tokens.group('PROBLEM')
            assert problem.id

            page = SiteSpoj._proxy.get(url)

            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteSpoj.xpath_problem_name)
                problem.name = (e and str(e[0])) or None
                #   - problem time limit,
                e = t.xpath(SiteSpoj.xpath_problem_time)
                p = e and e[0].strip()[:-1] # remove whitespace characters and 's' at the end
                problem.time_limit_ms = p and float(p) * 1000
                #   - problem source limit,
                e = t.xpath(SiteSpoj.xpath_problem_source)
                p = e and e[0].strip()[:-1] # remove whitespace characters and 'B' at the end
                problem.source_limit_kbyte = p and float(p) / 1000
                #   - problem memory limit,
                e = t.xpath(SiteSpoj.xpath_problem_memory)
                p = e and e[0].strip()[:-2] # remove whitespace characters and 'MB' at the end
                problem.memory_limit_kbyte = p and float(p) * 2**10
                #   - test inputs and outputs.
                e = t.xpath(SiteSpoj.xpath_problem_ins_outs)
                problem.inputs = [i.strip() for i in e[0:][::2]]
                problem.outputs = [o.strip() for o in e[1:][::2]]

                if (problem.name and
                    problem.time_limit_ms and
                    problem.source_limit_kbyte and
                    problem.memory_limit_kbyte and
                    problem.inputs and
                    problem.outputs):
                        problems.append(problem)
                else:
                    warn('Problem "' + problem.id + '" not fetched successfully!')

            else:
                warn('Problem "' + problem.id + '" does not exist on Spoj!')

        return problems
Пример #2
0
 def get_problems(self, urls):
     """Overridden.
     """
     problems = []
     for url in urls:
         problem = Problem()
         problem.url = url
         url_path = urlparse(url).path
         assert url_path
         tokens = SiteLocal.pattern_contest.search(url_path)
         problem.id = tokens.group('PROBLEM')
         assert problem.id
         problem.name = problem.id
         problem.time_limit_ms = self.time_limit_ms
         problem.memory_limit_kbyte = self.memory_limit_kbyte
         problem.source_limit_kbyte = self.source_limit_kbyte
         problems.append(problem)
     return problems
Пример #3
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteCodeChef.pattern_contest.search(url_path)
            problem.id = tokens.group("PROBLEM")
            assert problem.id
            problem.source_limit_kbyte = self.source_limit_kbyte

            page = SiteCodeChef._proxy.get(url)

            #TODO Implement the rest from here...
            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteCodeChef.xpath_problem_name)
                problem.name = (e and str(e[0])) or None
                #   - problem time limit,
                e = t.xpath(SiteCodeChef.xpath_problem_time)
                limit = e and float(e[0].split()[0]) * 1000
                problem.time_limit_ms = limit or self.time_limit_ms
                #   - problem memory limit,
                e = t.xpath(SiteCodeChef.xpath_problem_memory)
                limit = e and float(e[0].split()[0]) * 2**10
                problem.memory_limit_kbyte = limit or self.memory_limit_kbyte
                #   - test inputs,
                e = t.xpath(SiteCodeChef.xpath_problem_ins)
                problem.inputs = [os.linesep.join(inp.itertext()) for inp in e]
                #   - test outputs.
                e = t.xpath(SiteCodeChef.xpath_problem_outs)
                problem.outputs = [os.linesep.join(out.itertext()) for out in e]

                problems.append(problem)
        return problems
Пример #4
0
    def get_problems(self, urls):
        """Overridden.
        """
        problems = []
        for url in urls:
            problem = Problem()
            problem.url = url
            url_path = urlparse(url).path
            assert url_path
            tokens = SiteRosalind.pattern_contest.search(url_path)
            problem.id = tokens.group('PROBLEM')
            assert problem.id

            page = SiteRosalind._proxy.get(url)

            # Data from web (for each problem):
            if page.status_code == 200:
                t = html.fromstring(page.text)
                #   - problem name,
                e = t.xpath(SiteRosalind.xpath_problem_name)
                problem.name = (e and str(e[0]).strip()) or None
                #   - test input, (single fetched)
                e = t.xpath(SiteRosalind.xpath_problem_ins)
                problem.inputs = e and [str(e[0]).strip()]
                #   - test outputs, (single fetched)
                e = t.xpath(SiteRosalind.xpath_problem_outs)
                problem.outputs = e and [str(e[0]).strip()]

                if (problem.name and
                    problem.inputs and
                    problem.outputs):
                        problems.append(problem)
            else:
                warn('Problem "' + problem.id + '" does not exist on Rosalind!')

        return problems