Skip to content

Commit

Permalink
always fetch English attachment first
Browse files Browse the repository at this point in the history
  • Loading branch information
ZsgsDesign committed Oct 24, 2021
1 parent cf74c8e commit 144b02e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,23 @@ private function _extractCodeForces($pcode, $url)

if (stripos($content, "<title>Attachments") !== false) {
// refetching actual attachment
$attachmentDOM = HtmlDomParser::str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false);
$attachmentURL = $attachmentDOM->find('#pageContent div.datatable tbody tr a', 0)->href;
$attachmentURL = null;
$attachmentsDOM = HtmlDomParser::str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false);
foreach ($attachmentsDOM->find('#pageContent div.datatable tbody tr') as $attachmentDOM) {
if(filled($attachmentDOM->find('a', 0)) && trim($attachmentDOM->find('td', 1)->plaintext == 'English')) {
$attachmentURL = $attachmentDOM->find('a', 0)->href;
break;
}
}
if(blank($attachmentURL)) {
$firstAttachmentDOM = $attachmentsDOM->find('#pageContent div.datatable tbody tr a', 0);
if(filled($firstAttachmentDOM)) {
$attachmentURL = $firstAttachmentDOM->href;
} else {
$this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>Statement is not available.</>\n");
return false;
}
}
$url = $this->globalizeCodeForcesURL($attachmentURL);
$response = $this->getCodeForcesResponse($url);
$contentType = $response->headers['content-type'];
Expand Down
2 changes: 1 addition & 1 deletion babel.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "CodeForces Gym Interface for NOJ",
"license": "MIT",
"repository": "https://github.com/NJUPTAAA/NOJ_Extension_Babel_Gym",
"version": "0.1.3",
"version": "0.1.4",
"website": "https://codeforces.com/gyms",
"custom": {
"css": "resources/custom.css"
Expand Down

0 comments on commit 144b02e

Please sign in to comment.