Skip to content

Commit

Permalink
Merge pull request #630 from kmyk/fix/update-hr
Browse files Browse the repository at this point in the history
fix for HackerRank
  • Loading branch information
kawacchu authored Dec 4, 2019
2 parents 7a8c94a + be365d7 commit 973f1a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion onlinejudge/_implementation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def parse_content(parent: Union[bs4.NavigableString, bs4.Tag, bs4.Comment]) -> b

def new_session_with_our_user_agent() -> requests.Session:
session = requests.Session()
session.headers['User-Agent'] += ' (+{})'.format(version.__url__)
session.headers['User-Agent'] = '{}/{} (+{})'.format(version.__package_name__, version.__version__, version.__url__)
log.debug('User-Agent: %s', session.headers['User-Agent'])
return session


Expand Down
4 changes: 2 additions & 2 deletions onlinejudge/service/hackerrank.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def from_url(cls, url: str) -> Optional['HackerRankProblem']:
result = urllib.parse.urlparse(url)
if result.scheme in ('', 'http', 'https') \
and result.netloc in ('hackerrank.com', 'www.hackerrank.com'):
m = re.match(r'^/contests/([0-9A-Za-z-]+)/challenges/([0-9A-Za-z-]+)$', utils.normpath(result.path))
m = re.match(r'^/contests/([0-9A-Za-z-]+)/challenges/([0-9A-Za-z-]+)(/problem)?/?$', utils.normpath(result.path))
if m:
return cls(contest_slug=m.group(1), challenge_slug=m.group(2))
m = re.match(r'^/challenges/([0-9A-Za-z-]+)$', utils.normpath(result.path))
m = re.match(r'^/challenges/([0-9A-Za-z-]+)(/problem)?/?$', utils.normpath(result.path))
if m:
return cls(contest_slug='master', challenge_slug=m.group(1))
return None
Expand Down

0 comments on commit 973f1a8

Please sign in to comment.