@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use App\Http\Controllers\VirtualCrawler\CrawlerBase; |
| 6 | 6 | use App\Models\ProblemModel; |
| 7 | 7 | use KubAT\PhpSimple\HtmlDomParser; |
| 8 | -use Auth,Requests,Exception; |
|
| 8 | +use Auth, Requests, Exception; |
|
| 9 | 9 | |
| 10 | 10 | class PTA extends CrawlerBase |
| 11 | 11 | { |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return Response |
| 18 | 18 | */ |
| 19 | - public function __construct($action = 'crawl_problem', $con = 'all', $cached = false) |
|
| 19 | + public function __construct($action='crawl_problem', $con='all', $cached=false) |
|
| 20 | 20 | { |
| 21 | 21 | set_time_limit(0); // Pandora's box, engage! |
| 22 | 22 | if ($action=='judge_level') { |
@@ -34,39 +34,39 @@ discard block |
||
| 34 | 34 | public function crawling($conType) |
| 35 | 35 | { |
| 36 | 36 | $start=time(); |
| 37 | - $f = fopen(__DIR__."/pta_status.log", "w") or die("Unable to open file!"); |
|
| 38 | - if ($conType == 'all') { |
|
| 37 | + $f=fopen(__DIR__."/pta_status.log", "w") or die("Unable to open file!"); |
|
| 38 | + if ($conType=='all') { |
|
| 39 | 39 | // Here is the script |
| 40 | 40 | // |
| 41 | 41 | // var a=""; |
| 42 | 42 | // document.querySelectorAll('a[href^="/problem-sets/"]').forEach(v=>{a+=v.href.split("/")[4]+","}) |
| 43 | 43 | // console.log(a); |
| 44 | 44 | |
| 45 | - $conList=[12,13,14,15,16,17,434,994805046380707840,994805148990160896,994805260223102976,994805342720868352]; |
|
| 45 | + $conList=[12, 13, 14, 15, 16, 17, 434, 994805046380707840, 994805148990160896, 994805260223102976, 994805342720868352]; |
|
| 46 | 46 | } else { |
| 47 | 47 | $conList=[intval($conType)]; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | foreach ($conList as $con) { |
| 51 | - $this->con = $con; |
|
| 52 | - $this->imgi = 1; |
|
| 51 | + $this->con=$con; |
|
| 52 | + $this->imgi=1; |
|
| 53 | 53 | $problemModel=new ProblemModel(); |
| 54 | - $res = Requests::post("https://pintia.cn/api/problem-sets/$con/exams",[ |
|
| 54 | + $res=Requests::post("https://pintia.cn/api/problem-sets/$con/exams", [ |
|
| 55 | 55 | "Content-Type"=>"application/json" |
| 56 | - ],"{}"); |
|
| 56 | + ], "{}"); |
|
| 57 | 57 | |
| 58 | - if (strpos($res->body, 'PROBLEM_SET_NOT_FOUND') !== false) { |
|
| 58 | + if (strpos($res->body, 'PROBLEM_SET_NOT_FOUND')!==false) { |
|
| 59 | 59 | header('HTTP/1.1 404 Not Found'); |
| 60 | 60 | die(); |
| 61 | 61 | } else { |
| 62 | - $generalDetails=json_decode($res->body,true); |
|
| 62 | + $generalDetails=json_decode($res->body, true); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $now=time()-$start; |
| 66 | 66 | fwrite($f, "General Detail API Success at {$now}".PHP_EOL); |
| 67 | 67 | |
| 68 | - $probLists = json_decode(Requests::get( |
|
| 69 | - "https://pintia.cn/api/problem-sets/$con/problems?type=PROGRAMMING&exam_id=0",[ |
|
| 68 | + $probLists=json_decode(Requests::get( |
|
| 69 | + "https://pintia.cn/api/problem-sets/$con/problems?type=PROGRAMMING&exam_id=0", [ |
|
| 70 | 70 | "Content-Type"=>"application/json" |
| 71 | 71 | ] |
| 72 | 72 | )->body, true)["problemSetProblems"]; |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | fwrite($f, " Problems List API Success at {$now}".PHP_EOL); |
| 76 | 76 | |
| 77 | 77 | foreach ($probLists as $prob) { |
| 78 | - $probDetails = json_decode(Requests::get( |
|
| 79 | - "https://pintia.cn/api/problem-sets/$con/problems/{$prob["id"]}?exam_id=0",[ |
|
| 78 | + $probDetails=json_decode(Requests::get( |
|
| 79 | + "https://pintia.cn/api/problem-sets/$con/problems/{$prob["id"]}?exam_id=0", [ |
|
| 80 | 80 | "Content-Type"=>"application/json" |
| 81 | 81 | ] |
| 82 | 82 | )->body, true)["problemSetProblem"]; |
@@ -84,28 +84,28 @@ discard block |
||
| 84 | 84 | $now=time()-$start; |
| 85 | 85 | fwrite($f, " Problem Details API Success at {$now}".PHP_EOL); |
| 86 | 86 | |
| 87 | - $this->pro['pcode'] = 'PAT'.$prob["id"]; |
|
| 88 | - $this->pro['OJ'] = $this->oid; |
|
| 89 | - $this->pro['contest_id'] = $con; |
|
| 90 | - $this->pro['index_id'] = $prob["id"]; |
|
| 91 | - $this->pro['origin'] = "https://pintia.cn/problem-sets/$con/problems/{$prob["id"]}"; |
|
| 92 | - $this->pro['title'] = $prob["title"]; |
|
| 93 | - $this->pro['time_limit'] = $probDetails["problemConfig"]["programmingProblemConfig"]["timeLimit"]; |
|
| 94 | - $this->pro['memory_limit'] = $probDetails["problemConfig"]["programmingProblemConfig"]["memoryLimit"]; |
|
| 95 | - $this->pro['solved_count'] = $prob["acceptCount"]; |
|
| 96 | - $this->pro['input_type'] = 'standard input'; |
|
| 97 | - $this->pro['output_type'] = 'standard output'; |
|
| 98 | - |
|
| 99 | - $this->pro['description'] = str_replace("](~/","](https://images.ptausercontent.com/",$probDetails["content"]); |
|
| 100 | - $this->pro['description'] = str_replace("$$","$",$this->pro['description']); |
|
| 101 | - $this->pro['markdown'] = 1; |
|
| 102 | - $this->pro['tot_score'] = $probDetails["score"]; |
|
| 103 | - $this->pro["partial"] = 1; |
|
| 104 | - $this->pro['input'] = null; |
|
| 105 | - $this->pro['output'] = null; |
|
| 106 | - $this->pro['note'] = null; |
|
| 107 | - $this->pro['sample'] = []; |
|
| 108 | - $this->pro['source'] = $generalDetails["problemSet"]["name"]; |
|
| 87 | + $this->pro['pcode']='PAT'.$prob["id"]; |
|
| 88 | + $this->pro['OJ']=$this->oid; |
|
| 89 | + $this->pro['contest_id']=$con; |
|
| 90 | + $this->pro['index_id']=$prob["id"]; |
|
| 91 | + $this->pro['origin']="https://pintia.cn/problem-sets/$con/problems/{$prob["id"]}"; |
|
| 92 | + $this->pro['title']=$prob["title"]; |
|
| 93 | + $this->pro['time_limit']=$probDetails["problemConfig"]["programmingProblemConfig"]["timeLimit"]; |
|
| 94 | + $this->pro['memory_limit']=$probDetails["problemConfig"]["programmingProblemConfig"]["memoryLimit"]; |
|
| 95 | + $this->pro['solved_count']=$prob["acceptCount"]; |
|
| 96 | + $this->pro['input_type']='standard input'; |
|
| 97 | + $this->pro['output_type']='standard output'; |
|
| 98 | + |
|
| 99 | + $this->pro['description']=str_replace("](~/", "](https://images.ptausercontent.com/", $probDetails["content"]); |
|
| 100 | + $this->pro['description']=str_replace("$$", "$", $this->pro['description']); |
|
| 101 | + $this->pro['markdown']=1; |
|
| 102 | + $this->pro['tot_score']=$probDetails["score"]; |
|
| 103 | + $this->pro["partial"]=1; |
|
| 104 | + $this->pro['input']=null; |
|
| 105 | + $this->pro['output']=null; |
|
| 106 | + $this->pro['note']=null; |
|
| 107 | + $this->pro['sample']=[]; |
|
| 108 | + $this->pro['source']=$generalDetails["problemSet"]["name"]; |
|
| 109 | 109 | |
| 110 | 110 | $problem=$problemModel->pid($this->pro['pcode']); |
| 111 | 111 | |