Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cpcli/platforms/codeforces.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
from typing import List

import lxml
from lxml.html import document_fromstring

from cpcli.platforms import Platform
from cpcli.question import Question
from cpcli.utils.config import CpCliConfig
from cpcli.utils.uri import PlatformURI
from cpcli.utils.exceptions import InvalidProblemSetURI

logger = logging.getLogger()

Expand All @@ -22,14 +23,25 @@ def __init__(self, config: CpCliConfig, uri: PlatformURI):
def uri_prefix():
return 'cf'

def extra_message(self) -> str:
extra = ', Invalid Contest ID \n'
return extra

def get_questions(self) -> List[Question]:
contest = self.uri.problemset
logger.info(f'Downloading page {self.base_url}/contest/{contest}/problems')

body = self.download_response(f"/contest/{contest}/problems")
questions: List[Question] = []

doc = document_fromstring(body)
try:
doc = document_fromstring(body)

except lxml.etree.ParserError as parse_error:
if str(parse_error) == "Document is empty":
raise InvalidProblemSetURI(str(self.uri), self.extra_message()) from parse_error

raise
caption = doc.xpath('//div[@class="caption"]/text()')[0]

logger.info(f'Found: {caption} ✅')
Expand Down