Skip to content

Commit

Permalink
reconstructed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brethland committed Aug 6, 2019
1 parent 8c1d914 commit 2d5c3a1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function crawl($con)
$lastVolume = isset($_lastVolume)?$_lastVolume:56;
$HDUVolumePage = HtmlDomParser::str_get_html(Requests::get("http://acm.hdu.edu.cn/listproblem.php?vol=$lastVolume", ['Referer' => 'http://acm.hdu.edu.cn'])->body, true, true, DEFAULT_TARGET_CHARSET, false);
$_lastProbID = intval($HDUVolumePage->find('tr[height="22"]', -1)->find("td", 0)->plaintext);
$lastProbID = $_lastProbID != 0?$_lastProbID:6566;
$lastProbID = $_lastProbID != 0?$_lastProbID:6633;
foreach (range(1000, $lastProbID) as $probID) {
$this->_crawl($probID, 5);
}
Expand Down
17 changes: 10 additions & 7 deletions Judger.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function __construct()
private function grab($all_data) {
$oj = $all_data['oj'];
$handle = $all_data['handle'];
$vcid = $all_data['vcid'];
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $all_data['site']);
Expand All @@ -43,8 +44,8 @@ private function grab($all_data) {


$headers = array();
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/{$oj}_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/{$oj}_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie"));

$result = curl_exec($ch);
curl_close($ch);
Expand All @@ -57,7 +58,8 @@ private function _loginAndGet($url,$handle,$pass,$vcid)
$response=$curl->grab_page([
'site' => 'http://acm.hdu.edu.cn/contests/contest_show.php?cid='.$vcid,
'oj' => 'hdu',
'handle' => $handle
'handle' => $handle,
"vcid" => $vcid,
]);
if (strpos($response, 'Sign In')!==false) {
$ch = curl_init();
Expand All @@ -78,8 +80,8 @@ private function _loginAndGet($url,$handle,$pass,$vcid)
$headers[] = 'Referer: http://acm.hdu.edu.cn/userloginex.php?cid='.$vcid;
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8';
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$vcid}{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$vcid}{$handle}.cookie"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_HEADER,true);

Expand All @@ -90,6 +92,7 @@ private function _loginAndGet($url,$handle,$pass,$vcid)
'site'=>$url,
'oj'=>'hdu',
'handle'=>$handle,
'vcid'=>$vcid,
]);
}

Expand All @@ -98,7 +101,7 @@ public function judge($row)
$sub = [];
if(!isset($row['vcid'])) {
$response = Requests::get("http://acm.hdu.edu.cn/status.php?first=".$row['remote_id'])->body;
if(!$response || isnull($response)) { throw new Exception("Cannot grab page."); return;}
if(!$response) { throw new Exception("Cannot grab page."); return;}
preg_match ('/<\/td><td>[\\s\\S]*?<\/td><td>[\\s\\S]*?<\/td><td>([\\s\\S]*?)<\/td><td>[\\s\\S]*?<\/td><td>(\\d*?)MS<\/td><td>(\\d*?)K<\/td>/', $response, $match);
if(strpos(trim(strip_tags($match[1])), 'Runtime Error')!==false) $sub['verdict'] = 'Runtime Error';
else $sub['verdict'] = $this->verdict[trim(strip_tags($match[1]))];
Expand All @@ -118,7 +121,7 @@ public function judge($row)
$handle = $judger['handle'];
$pass = $judger['password'];
$response = $this->_loginAndGet("http://acm.hdu.edu.cn/contests/contest_status.php?cid=".$row['vcid']."&user=".$handle."&pid=".$iid, $handle, $pass, $row['vcid']);
if(!$response || isnull($response)) { throw new Exception("Cannot grab page."); return;}
if(!$response) { throw new Exception("Cannot grab page."); return;}
$hduRes = HTMLDomParser::str_get_html($response, true, true, DEFAULT_TARGET_CHARSET, false);
foreach($hduRes->find('tr') as $ele) {
$elements=$ele->children();
Expand Down
28 changes: 15 additions & 13 deletions Submitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ private function _submit()
private function grab($all_data) {
$oj = $all_data['oj'];
$handle = $all_data['handle'];
$vcid = $all_data['vcid'];
$ch = curl_init();

// Log::alert($all_data['site']);
curl_setopt($ch, CURLOPT_URL, $all_data['site']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


$headers = array();
// $headers[] = 'Cookie: PHPSESSID=1uv8lhltg2ceas7d8qtgon0cc2';
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/{$oj}_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/{$oj}_{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/{$oj}_{$vcid}{$handle}.cookie"));

$result = curl_exec($ch);
curl_close($ch);
Expand All @@ -112,7 +110,8 @@ private function __loginAndGet($url)
$response=$curl->grab_page([
'site' => 'http://acm.hdu.edu.cn/contests/contest_show.php?cid='.$this->post_data['vcid'],
'oj' => 'hdu',
'handle' => $this->selectedJudger["handle"]
'handle' => $this->selectedJudger["handle"],
"vcid" => $this->post_data['vcid'],
]);
if (strpos($response, 'Sign In')!==false) {
$ch = curl_init();
Expand All @@ -133,8 +132,8 @@ private function __loginAndGet($url)
$headers[] = 'Referer: http://acm.hdu.edu.cn/userloginex.php?cid='.$this->post_data['vcid'];
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8';
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->post_data['vcid']}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->post_data['vcid']}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_HEADER,true);

Expand All @@ -145,6 +144,7 @@ private function __loginAndGet($url)
'site'=>$url,
'oj'=>'hdu',
'handle'=>$this->selectedJudger["handle"],
'vcid' => $this->post_data['vcid'],
]);
}

Expand All @@ -154,7 +154,8 @@ private function _contestLogin()
$response=$curl->grab_page([
'site' => 'http://acm.hdu.edu.cn/contests/contest_show.php?cid='.$this->post_data['vcid'],
'oj' => 'hdu',
'handle' => $this->selectedJudger["handle"]
'handle' => $this->selectedJudger["handle"],
'vcid' => $this->post_data['vcid'],
]);
if (strpos($response, 'Sign In')!==false) {
$ch = curl_init();
Expand All @@ -175,8 +176,8 @@ private function _contestLogin()
$headers[] = 'Referer: http://acm.hdu.edu.cn/userloginex.php?cid='.$this->post_data['vcid'];
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8';
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->post_data['vcid']}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->post_data['vcid']}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_HEADER,true);

Expand Down Expand Up @@ -204,13 +205,14 @@ private function contestSubmit() {
"ret" => true,
"follow" => false,
"returnHeader" => true,
"handle" => $this->selectedJudger["handle"]
"handle" => $this->selectedJudger["handle"],
'vcid'=>$this->post_data['vcid'],
]);
$this->sub['jid'] = $this->selectedJudger['jid'];
$this->sub['vcid'] = $vcid;
$res = $this->__loginAndGet("http://acm.hdu.edu.cn/contests/contest_status.php?cid={$vcid}&user=".$this->selectedJudger['handle'].'&pid='.$this->post_data['iid']);
if (!preg_match('/<td height=22>([\s\S]*?)<\/td>/', $res, $match)) {
sleep(5);
sleep(7);
$this->sub['verdict']='Submission Error';
} else {
$this->sub['remote_id']=$match[1];
Expand Down
15 changes: 9 additions & 6 deletions Synchronizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ private function _loginAndGet($url)
{
$curl = new Curl();
$response=$curl->grab_page([
'site' => "http://acm.hdu.edu.cn/contests/contest_show.php?cid=".$this->vcid,
'site' => "http://acm.hdu.edu.cn/userloginex.php?cid=".$this->vcid,
'oj' => 'hdu',
'handle' => $this->selectedJudger["handle"]
'handle' => $this->selectedJudger["handle"],
'vcid' => $this->vcid,
]);
if (strpos($response, 'Sign In')!==false) {

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://acm.hdu.edu.cn/userloginex.php?action=login&cid='.$this->vcid.'&notice=0');
Expand All @@ -63,8 +65,8 @@ private function _loginAndGet($url)
$headers[] = 'Referer: http://acm.hdu.edu.cn/userloginex.php?cid='.$this->vcid;
$headers[] = 'Accept-Encoding: gzip, deflate';
$headers[] = 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8';
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEFILE, babel_path("Cookies/hdu_{$this->vcid}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_COOKIEJAR, babel_path("Cookies/hdu_{$this->vcid}{$this->selectedJudger['handle']}.cookie"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_HEADER,true);

Expand All @@ -75,6 +77,7 @@ private function _loginAndGet($url)
'site'=>$url,
'oj'=>'hdu',
'handle'=>$this->selectedJudger["handle"],
'vcid' => $this->vcid,
]);
}

Expand Down Expand Up @@ -185,7 +188,7 @@ public function crawlProblem($con)
public function crawlContest() {
$contestModel = new ContestModel();
$res = iconv("gb2312","utf-8//IGNORE",$this->_loginAndGet("http://acm.hdu.edu.cn/contests/contest_show.php?cid=".$this->vcid));
if(isnull($res)) { throw new Exception("Cannot grab page.");return; }
if(!$res) { throw new Exception("Cannot grab page.");return; }
$contestInfo = [
'name' => self::find('/<h1[\s\S]*?>([\s\S]*?)<\/h1>/',$res),
'begin_time' => self::find('/Start Time : ([\s\S]*?)&/',$res),
Expand Down Expand Up @@ -235,7 +238,7 @@ public function crawlClarification()
public function _clarification($id)
{
$res = iconv("gb2312","utf-8//IGNORE",$this->_loginAndGet("http://acm.hdu.edu.cn/viewnotify.php?id={$id}&cid=".$this->vcid));
if(isnull($res)) { throw new Exception("Cannot grab page.");return false; }
if(!$res) { throw new Exception("Cannot grab page.");return false; }
if(strpos($res,"No such notification.") !== false) { return false; }
$contestModel = new ContestModel();
if(($contestModel->remoteAnnouncement($this->vcid."-".$id))!=null) {
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": "HDU Interface for NOJ",
"license": "MIT",
"repository":"https://github.com/NJUPTAAA/NOJ_Extension_HDU",
"version":"0.3.17",
"version":"0.3.18",
"website":"http://acm.hdu.edu.cn/",
"custom":{
"css":"resources/custom.css"
Expand Down

0 comments on commit 2d5c3a1

Please sign in to comment.